【发布时间】:2017-07-23 03:09:14
【问题描述】:
我有一个关于 BitMapFactory.decodeFile 的问题。
在我的应用中,我希望用户能够从他/她的设备中选择图像或拍照。然后必须将其显示在 ImageView 中
这里是代码sn-p:
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)
如何解决。请帮助我。提前谢谢..
【问题讨论】:
-
对于Android Q,请参见下面的解决方案:stackoverflow.com/a/57804657/1015686
标签: android filenotfoundexception bitmapfactory