`getContentResolver (). openInputStream (uri) `throws a FileNotFoundException

I use this intention so that the user can 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 a FileNotFoundException on some Android devices.

uri value:

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

An exception:

 java.io.FileNotFoundException: No such file or directory 

And itโ€™s very strange that it will not throw this exception on some other Android devices. What will cause this error and how to fix it?

+6
source share
3 answers
 MediaStore.Images.Media.INTERNAL_CONTENT_URI 

for images on a local device or

 MediaStore.Images.Media.EXTERNAL_CONTENT_URI 

for images on an SD card.

Are you sure you are accessing them correctly? Internal / external treatment depends on the device, which may be why his work on some, but not with others.

+2
source

I have the same problem, but I solved it using the setImageURI method for ImageView.

You do not need to use the following code:

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

Just use the following function:

 imageViewCustomer.setImageURI(data.getData()); 
+1
source

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

-1
source

All Articles