【问题标题】:BitmapFactory.decodeFile e/bitmapfactory unable to decode stream java.io.filenotfoundexception EACCES (Permission denied)BitmapFactory.decodeFile e/bitmapfactory 无法解码流 java.io.filenotfoundexception EACCES(权限被拒绝)
【发布时间】:2020-07-15 12:25:24
【问题描述】:

我尝试从存储中拍照,并使用 BitmapFactory.decodeFile 在 ImageView 中显示它,但我发现错误无法解码流 java.io.filenotfoundexception EACCES(权限被拒绝),我使用的是 android 10 模拟器 API 30。

这是我的代码:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK)
        {
            if(requestCode == REQUEST_GALLERY)
            {
                Uri dataimage = data.getData();
                String[] imageprojection = {MediaStore.Images.Media.DATA};
                Cursor cursor = getContentResolver().query(dataimage,imageprojection,null,null,null);

                if (cursor != null)
                {
                    cursor.moveToFirst();
                    int indexImage = cursor.getColumnIndex(imageprojection[0]);
                    part_image = cursor.getString(indexImage);

                    Toast.makeText(this, "Image Saved Part Image :" + part_image, Toast.LENGTH_SHORT).show();

                    if(part_image != null)
                    {
                        File image = new File(part_image);
                        imgHolder.setImageBitmap(BitmapFactory.decodeFile(image.getAbsolutePath()));
                        Toast.makeText(this, "Image Saved Part Image :" + image, Toast.LENGTH_SHORT).show();
                    }
                }
            }
        }
    }
    

我已将此添加到我的 Android 清单中:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

还有这个:

<application
...
android:requestLegacyExternalStorage="true">

这是我的错误日志:

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/0000-0000/DCIM/Camera/IMG-20200714-WA0008.jpg: open failed: EACCES (Permission denied)

任何帮助解决方案?

【问题讨论】:

    标签: android permission-denied bitmapfactory


    【解决方案1】:
    imgHolder.setImageUri(data.getData());
    

    【讨论】:

      猜你喜欢
      • 2020-05-17
      • 2019-04-20
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多