How to get bitmap providing a URI, java.io.FileNotFoundException: No content provider: /sdcard/Hello/1310610722879.jpg

谁说我不能喝 提交于 2019-12-05 17:56:05

问题


I've read the example to do this:

 protected void onActivityResult(int requestCode, int resultCode, Intent data)
 {
     super.onActivityResult(requestCode, resultCode, data);
     if (resultCode == RESULT_OK)
     {
         Uri imageUri = data.getData();
         Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),              imageUri);
     }
 }

But i get java.io.FileNotFoundException: No content provider: /sdcard/Hello/1310610722879.jpg

My code is here:

Uri uri1 = Uri.parse(Config.getPhotoPath(this));                
try {
    Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri1);
    attachButton.setImageBitmap(bitmap);
} catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
}

Any ideas how to make it work?

Ok I messed around, u have to do this:

Uri uri1 = Uri.parse("file://" + Config.getPhotoPath(this));

回答1:


Ok I messed around, u have to do this:

Uri uri1 = Uri.parse("file://" + Config.getPhotoPath(this));



回答2:


Or you can do

File file = new file(Config.getPhotoPath(this));
Uri uri1 = Uri.fromFile(file);


来源:https://stackoverflow.com/questions/6687926/how-to-get-bitmap-providing-a-uri-java-io-filenotfoundexception-no-content-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!