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

2

12

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));
Chavez answered 14/7, 2011 at 2:44 Comment(0)
C
25

Ok I messed around, u have to do this:

Uri uri1 = Uri.parse("file://" + Config.getPhotoPath(this));
Chavez answered 5/9, 2011 at 5:27 Comment(3)
it would be great is they can add that MIME type needs to added manually in api documentation than just adding RFC 2396 compliant :/Orthoclase
I couldnt find the method Config.getPhotoPath(), also you haven't specified imageUri in in your code,how are you still able to retrieve the image ?Jocundity
yeh what is Config here??Transparency
S
7

Or you can do

File file = new file(Config.getPhotoPath(this));
Uri uri1 = Uri.fromFile(file);
Staceestacey answered 7/10, 2014 at 19:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.