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));
antonio
  • 17,678
  • 4
  • 47
  • 57
Maurice
  • 6,343
  • 13
  • 50
  • 76

2 Answers2

25

Ok I messed around, u have to do this:

Uri uri1 = Uri.parse("file://" + Config.getPhotoPath(this));
antonio
  • 17,678
  • 4
  • 47
  • 57
Maurice
  • 6,343
  • 13
  • 50
  • 76
  • 1
    it would be great is they can add that MIME type needs to added manually in api documentation than just adding RFC 2396 compliant :/ – amIT Aug 21 '15 at 11:15
  • 2
    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 ? – akshay7692 Apr 24 '16 at 06:16
7

Or you can do

File file = new file(Config.getPhotoPath(this));
Uri uri1 = Uri.fromFile(file);
antonio
  • 17,678
  • 4
  • 47
  • 57
Helin Wang
  • 3,780
  • 1
  • 27
  • 31