本文介绍了BitmapFactory:无法解码流:java.io.FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于BitMapFactory.decodeFile的问题.
I have a problem concerning the BitMapFactory.decodeFile.
在我的应用中,我希望用户能够从他/她的设备中选择图像或拍照.然后必须将其显示在ImageView中
In my app, I want to user to be able to select an image from his/her device or take a photograph. This must then be displayed in an ImageView
这是代码段:
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
MyImage image = new MyImage();
image.setTitle("Test");
image.setDescription("test choose a photo from gallery and add it to " + "list view");
image.setDatetime(System.currentTimeMillis());
image.setPath(picturePath);
我得到了这个例外:
BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20170302-WA0012.jpg: open failed: EACCES (Permission denied)
解决方法.请帮助我.谢谢..
How to resolve it.Please help me.Thanks in advance..
推荐答案
它的权限问题,您需要在清单中添加外部读取存储的权限,然后才能使用它;如果使用的操作系统高于6.0,则您需要使用简单"权限.
Its permission issue, you need to add permission in manifest for external read storage then after you can able to use it and if you are using os above 6.0 then you need use Easy permission.
写:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
阅读:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
6.0以上:
private String[] galleryPermissions = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
if (EasyPermissions.hasPermissions(this, galleryPermissions)) {
pickImageFromGallery();
} else {
EasyPermissions.requestPermissions(this, "Access for storage",
101, galleryPermissions);
}
这篇关于BitmapFactory:无法解码流:java.io.FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!