12

I use this intent to let user select a photo:

Intent intent = new Intent(Intent.ACTION_PICK, 
                           MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(intent, INTENT_SELECT_PHOTO);

And in onActivityResult:

Uri uri = data.getData();
InputStream inputStream = getContentResolver().openInputStream(uri);

But it throws FileNotFoundException on some android devices.

The value of uri:

content://media/external/images/media/26467

The exception thrown:

java.io.FileNotFoundException: No such file or directory

And it's very strange that it won't throw this exception on some other android devices. What will cause this error and how to fix it?

Freewind
  • 193,756
  • 157
  • 432
  • 708

3 Answers3

3
MediaStore.Images.Media.INTERNAL_CONTENT_URI 

for images on the local device or

MediaStore.Images.Media.EXTERNAL_CONTENT_URI 

for images on the SD card.

Are you sure you are addressing both correctly? The internal/external treatment varies with device, maybe that is why its working on some but not on others.

Shakti
  • 1,581
  • 2
  • 20
  • 33
  • 3
    I just found that because the actual images are deleted, but they have caches in the photo viewer application. – Freewind Nov 25 '12 at 09:13
  • Good to know, searching for problem i ran into something that explains a related issue http://code.google.com/p/android/issues/detail?id=12508 – Shakti Nov 25 '12 at 09:17
  • Right Freewind, I had this exact code/error browsing my download folder for a .txt file and there where to downloads and both were about the same size, one worked one did not. Thanks! – tom Jun 12 '16 at 23:06
0

I face the same problem but I resolved it by using the setImageURI method of the ImageView.

You dont have to use the following code:

InputStream inputStream = getContentResolver().openInputStream(uri);

Simply use the following function:

imageViewCustomer.setImageURI(data.getData());
Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
Sfaruq681
  • 121
  • 6
-2

Use Context.getContentResolver().openInputStream(Uri);

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
Archie
  • 11