StorageException:权限被拒绝

时间:2020-02-29 10:21:42

标签: android firebase firebase-storage

此代码进入catch块,已授予存储权限。我没收到问题。

这是代码-

                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没有此问题。

2 个答案:

答案 0 :(得分:2)

将此行添加到清单中的application标记下,它应该可以工作- android:requestLegacyExternalStorage="true"

答案 1 :(得分:0)

将此代码添加您的清单权限。

req.query