hbuilder 4.87离线打包后,用Android studio打包,不能查看.db .zip格式的文件,能查看图片格式的文件,用云打包就能查看到.db .zip 这些格式的文件,是为什么,离线打包缺少了权限配置吗,还是什么情况???
//点击文件夹,查看文件操作
function toFolder(event) {
folderArr.value = [];
fileArr.value = [];
selectValue.value = "";
selectFile.value = null;
addressBar.value.push(event)
const files = plus.android.invoke(event.file, "listFiles");
if (files == null || files == '') {
inaccessible.value = true;
}
console.warn('files',files)
const { folderArrList, fileArrList } = formaterFiles(files);
folderArr.value = folderArrList;
fileArr.value = fileArrList;
}
function formaterFiles(files) {
uni.showLoading({
title: '正在读取文件'
});
const folderArrList = [];
const fileArrList = [];
files?.forEach((file) => {
// 过滤隐藏文件
if (!plus.android.invoke(file, "isHidden")) {
// 判断是文件还是文件夹
if (plus.android.invoke(file, "isDirectory")) {
const folderName = plus.android.invoke(file, "getName")
folderArrList.push({ name: folderName, file })
} else {
const fileName = plus.android.invoke(file, "getName")
console.log("fileName==============", fileName)
const types = fileName.split('.');
const type = types[types.length - 1];
console.log("type==============", type)
if (props.filterArr.length > 0 && !props.filterArr.includes(type)) {
return
}
else if (type.search(/txt/i) > -1) {
// txt 文件
fileArrList.push({ name: fileName, file: file, type: 'txt', select: false })
}
else if (type.search(/doc|docx/i) > -1) {
// doc/docx 文件
fileArrList.push({ name: fileName, file: file, type: 'doc', select: false })
}
else if (type.search(/pdf/i) > -1) {
// pdf 文件
fileArrList.push({ name: fileName, file: file, type: 'pdf', select: false })
}
else if (type.search(/zip/i)) {
// pdf 文件
fileArrList.push({ name: fileName, file: file, type: 'zip', select: false })
}
else if (type.search(/db/i)) {
// pdf 文件
fileArrList.push({ name: fileName, file: file, type: 'db', select: false })
}
else {
// 其他文件
fileArrList.push({ name: fileName, file: file, type: 'file', select: false })
}
}
}
})
1 个回复
Ask小助手 - Ask社区AI助手
离线打包后看不到 .db / .zip 文件,而云打包正常,基本可以确定是「权限 + targetSdkVersion」两个点没对齐。
Android 11 以后,Google 启用了分区存储(Scoped Storage),默认只能拿到自己沙盒里的文件,外部存储里非媒体文件(zip、db 等)即使 READ_EXTERNAL_STORAGE 也读不到;云打包默认把 targetSdkVersion 设成 29 并自动加上
android:requestLegacyExternalStorage="true",所以还能兼容旧行为。离线打包工程如果 targetSdkVersion ≥ 30 且没加 legacy 标志,就会出现你现在的情况:图片(媒体文件)能列出来,zip/db 被过滤掉。解决步骤
android/app/src/main/AndroidManifest.xml的<application>节点里补上build.gradle里compileSdkVersion/targetSdkVersion暂时不要超过 30;如果确实要 30+,则必须走 Storage Access Framework 或申请MANAGE_EXTERNAL_STORAGE(Google 审核严格,不推荐)。READ_EXTERNAL_STORAGE申请到「始终允许」;Android 13+ 还要再申请READ_MEDIA_IMAGES、READ_MEDIA_VIDEO、READ_MEDIA_AUDIO。./gradlew assembleRelease打包即可。这样离线包的行为就和云打包一致了,zip、db 文件都能正常枚举出来。
要回复问题请先登录或注册
公告
更多>相关问题