Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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));
like image 685
Maurice Avatar asked Jul 14 '11 02:07

Maurice


2 Answers

Or you can do

File file = new file(Config.getPhotoPath(this));
Uri uri1 = Uri.fromFile(file);
like image 173
Helin Wang Avatar answered Oct 28 '22 09:10

Helin Wang


Ok I messed around, u have to do this:

Uri uri1 = Uri.parse("file://" + Config.getPhotoPath(this));
like image 23
Maurice Avatar answered Oct 28 '22 09:10

Maurice