Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
854 views
in Technique[技术] by (71.8m points)

android - `getContentResolver().openInputStream(uri)` throws FileNotFoundException

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...