我正在尝试从 Uri
检索图像,首先我从图库中选择图像,然后使用 Intent 传递 imagePath 并尝试从 Uri
获取图像通过使用此代码 -
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
你可以看到我的 imgUri
上有 uri
,不知道做错了什么或遗漏了什么,如果有人知道遗漏了什么,请纠正我,谢谢: )
我正在使用 genyMotion 模拟器,这是问题的原因吗?
最佳答案
将此权限附加到您的 AndroidManifest.xml
文件中
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
和使用
Uri imgUri = Uri.parse("file://"+getIntent().getExtras().getString("imageUri"));
关于java - 将 uri 转换为位图时出现 "No content provider execution "错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34873935/