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
  • 18,044
  • 4
  • 45
  • 61
Maurice
  • 6,413
  • 13
  • 51
  • 76

2 Answers2

25

Ok I messed around, u have to do this:

Uri uri1 = Uri.parse("file://" + Config.getPhotoPath(this));
antonio
  • 18,044
  • 4
  • 45
  • 61
Maurice
  • 6,413
  • 13
  • 51
  • 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
  • yeh what is Config here?? – 68060 Aug 30 '23 at 23:41
7

Or you can do

File file = new file(Config.getPhotoPath(this));
Uri uri1 = Uri.fromFile(file);
antonio
  • 18,044
  • 4
  • 45
  • 61
Helin Wang
  • 4,002
  • 1
  • 30
  • 34