`getContentResolver()。openInputStream(URI)`抛出FileNotFoundException异常 [英] `getContentResolver().openInputStream(uri)` throws FileNotFoundException
问题描述
我用这个意图,让用户选择一张照片:
意向意图=新意图(Intent.ACTION_PICK,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(意向,INTENT_SELECT_PHOTO);
而在的onActivityResult
:
开放的URI = data.getData();
为InputStream的InputStream = getContentResolver()openInputStream(URI)。
但它抛出 FileNotFoundException异常
上的一些Android设备。
的值 URI
:
内容://媒体/外部/图像/媒体/ 26467
引发的异常:
java.io.FileNotFoundException:没有这样的文件或目录
和它很奇怪,它不会抛出一些其他的Android设备此异常。什么将导致此错误,以及如何解决它?
MediaStore.Images.Media.INTERNAL_CONTENT_URI
在本地设备上的图像或
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
在SD卡上的图像。
您一定要正确处理两者兼而有之?内部/外部治疗设备不同而不同,这也许就是为什么它的一些但不是别人的工作。
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?
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.
这篇关于`getContentResolver()。openInputStream(URI)`抛出FileNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!