我正在尝试从Uri
检索图像,首先我从图库中选择了图像,然后使用意图传递了imagePath并尝试使用此代码从Uri
获取图像 - < / p>
Uri imgUri = Uri.parse(getIntent().getExtras().getString("imageUri"));
Log.d("" + imgUri, " here it is");
InputStream PIS;
try {
PIS = getContentResolver().openInputStream(imgUri);
mImage = BitmapFactory.decodeStream(PIS);
} catch (Exception e){
Log.d("go home you're drunk "+e,"");
Toast toast = Toast.makeText(this, ""+e, Toast.LENGTH_LONG);
toast.show();
}
但是收到此错误
01-19 04:59:50.627 847-858/? I/ActivityManager: START u0 {cmp=pb.imagepicker/.CropActivity (has extras)} from uid 10060 on display 0
01-19 04:59:50.668 6072-6072/? D//storage/emulated/0/DCIM/Camera/IMG_20160118_124651.jpg: here it is
01-19 04:59:50.668 6072-6072/? D/go home you're drunk java.io.FileNotFoundException: No content provider: /storage/emulated/0�di[ 01-19 04:59:50.769 6072: 6085 W/EGL_emulation: eglSurfaceAttrib not implemented
//一些额外的错误
01-19 05:33:06.419 6565-6580/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe8e32360, error=EGL_SUCCESS
01-19 05:33:06.564 6565-6580/? W/EGL_emulation: eglSurfaceAttrib not implemented
01-19 05:33:06.564 6565-6580/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe8e328c0, error=EGL_SUCCESS
你可以看到我的uri
上有imgUri
,如果有人知道缺少什么,不知道出错了什么或遗失了,请纠正我,谢谢:)
我使用genyMotion模拟器是否是问题的原因?
答案 0 :(得分:5)
将此权限附加到AndroidManifest.xml
文件中
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
并使用
Uri imgUri = Uri.parse("file://"+getIntent().getExtras().getString("imageUri"));
答案 1 :(得分:0)
遇到了同样的问题,也许它的发生是因为你的模拟器改变了我的模拟器工作,我从genymotion转移到blueStack,它的工作原因不知道为什么会发生,你应该试一试