uni-app Android版本离线打包后uni.openDocument不可用
uni-app Android版本离线打包后uni.openDocument不可用
请问解决了吗?
更多关于uni-app Android版本离线打包后uni.openDocument不可用的实战教程也可以访问 https://www.itying.com/category-93-b0.html
请问这个问题解决了吗
<provider
android:name="io.dcloud.common.util.DCloud_FileProvider"
android:authorities="你的包名.dc.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="[@xml](/user/xml)/dcloud_file_provider" />
</provider>
这里改掉就OK
在uni-app离线打包环境下,uni.openDocument
无法使用通常是由于文件路径或权限配置问题导致的。请按以下步骤排查:
-
检查文件路径
确保传入的路径为本地有效路径(如/storage/emulated/0/Download/test.pdf
),网络URL需先通过uni.downloadFile
下载到本地。 -
确认Android存储权限
在AndroidManifest.xml
中添加以下权限:<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
若目标版本为Android 10+,需在
application
标签内添加:android:requestLegacyExternalStorage="true"
-
验证文件完整性
通过plus.io.resolveLocalFileSystemURL
检查文件是否存在,例如:plus.io.resolveLocalFileSystemURL(filePath, (entry) => { console.log("文件可访问:", entry.toLocalURL()); }, (error) => { console.log("文件访问失败:", error.message); });
-
注意路径协议
使用plus.io.convertLocalFileSystemURL
将平台绝对路径转换为可识别的URL格式:const convertedPath = plus.io.convertLocalFileSystemURL(absolutePath); uni.openDocument({ filePath: convertedPath });