此代码来捕获块,已授予存储权限。我没有得到这个问题。
这里是代码-
try {
boolean created = outputFile.createNewFile();
//Convert bitmap to byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
//write the bytes in file
FileOutputStream fos = new FileOutputStream(outputFile);
fos.write(bitmapdata);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
这里是例外
2020-02-29 15:46:38.238 25650-25650/com.startech.kiva E/StorageException: Permission denied
java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively0(Native Method)
at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
at java.io.File.createNewFile(File.java:1008)
at com.google.firebase.storage.FileDownloadTask.processResponse(com.google.firebase:firebase-storage@@19.1.0:136)
at com.google.firebase.storage.FileDownloadTask.run(com.google.firebase:firebase-storage@@19.1.0:227)
at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.0:1072)
at com.google.firebase.storage.StorageTask$$Lambda$12.run(Unknown Source:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
2020-02-29 15:46:38.238 25650-25650/com.startech.kiva E/com.ks.wallz.helpers.FirebaseDownloadHelper$1: An unknown error occurred, please check the HTTP result code and inner exception for server response.
更新刚刚检查了我的Android 10是否存在此问题,我的其他android 8没有此问题。
我认为您需要添加此内容:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
将此代码添加您的清单权限。
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
将此行添加到清单中的应用程序标记下,它应该可以工作-android:requestLegacyExternalStorage="true"