BitmapFactory.decodeFile e/BitmapFactory无法解码流java.io.filenot



我试图从存储中拍摄照片,并使用BitmapFactory.decodeFile在ImageView中显示它,但我发现错误无法解码流java.io.filenotfoundexception EACCES(权限被拒绝(,我使用的是安卓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)

有什么帮助的解决方案吗?

imgHolder.setImageUri(data.getData());

最新更新