【发布时间】:2022-01-03 16:33:36
【问题描述】:
我无法在 android 11 版本的设备上下载文件。
**Details :**
cordova android 10.1.0
"cordova-plugin-file" version="6.0.2"
"cordova-plugin-file-transfer" version="1.7.1"
"cordova-plugin-filepath" version="1.6.0"
**My Code:**
下面的代码是我为下载文件设备而编写的,它在 android 9 和 10 中工作,当我以 SDK 30 为目标时,它不工作并且仅在 android 11 中失败。
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function(dir) {
dir.getFile("test.pdf", {create:true}, function(file) {
file.createWriter(function(fileWriter) {
fileWriter.write("byteArrays data");
alert('Message', 'File Downloaded Successfully');
}, function(){
alert('Error!', "Unable to save the file");
});
},function(e){
alert('Error!', e);
});
},function(e){
console.log(e);
});
**I tried with below code in Androidmainfest file**
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACTION_MANAGE_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
**Config.xml file**
<preference name="AndroidInsecureFileModeEnabled" value="true" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
如果有任何遗漏,请告诉我,提前致谢。
【问题讨论】:
-
是的。您没有告诉您尝试创建的文件的完整路径。并且“不工作”你没有给出问题描述。
-
@blackapps 获取 base64 数据并使用 new Blob 转换为 pdf 并保存到设备中。让我知道是否有任何解决方案。从前几天开始尝试 nthg 工作,但相同的代码在 android 9 和 10 中工作。
-
重复:您没有告诉您尝试创建的文件的完整路径。
-
@blackapps 我的系统路径是 - /storage/emulated/0/