我无法在 Android 11 版本设备中下载文件。
\n**Details :**\n\ncordova android 10.1.0 \n"cordova-plugin-file" version="6.0.2" \n"cordova-plugin-file-transfer" version="1.7.1" \n"cordova-plugin-filepath" version="1.6.0" \n\n**My Code:**\nRun Code Online (Sandbox Code Playgroud)\n下面的代码是我编写的下载文件设备,它在 android 9 和 10 中工作,当我以 SDK 30 为目标时,它不起作用并且仅在 android 11 中失败。
\nwindow.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function(dir) {\n dir.getFile("test.pdf", {create:true}, function(file) {\n file.createWriter(function(fileWriter) {\n fileWriter.write("byteArrays data");\n alert('Message',\xc2\xa0'File Downloaded Successfully');\n }, function(){\n alert('Error!', "Unable to save the file");\n });\n },function(e){\n alert('Error!', e);\n });\n},function(e){\n console.log(e);\n});\n\n**I tried with below code in Androidmainfest file**\n\n<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />\n<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />\n<uses-permission android:name="android.permission.ACTION_MANAGE_STORAGE" />\n<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>\n\n\n\n**Config.xml file**\n<preference name="AndroidInsecureFileModeEnabled" value="true" />\n<preference name="AndroidPersistentFileLocation" value="Compatibility" />\nRun Code Online (Sandbox Code Playgroud)\n如果有任何遗漏,请告诉我,提前谢谢。
\n我发现downloadFile插件Cordova Advanced HTTP的方法是下载文件的好方法。我创建了这个示例应用程序来展示它是如何工作的。
请注意,该MANAGE_EXTERNAL_STORAGE权限在 Android 11 中已基本被弃用,因此您无法再下载到共享存储(例如,cordova.file.externalRootDirectory由许多应用程序共享 - 存在隐私和安全风险)。尝试您的应用程序范围内的目录之一,例如cordova.file.externalDataDirectory.
| 归档时间: |
|
| 查看次数: |
2866 次 |
| 最近记录: |