将uri转换为Bitmap时出现"无内容提供程序执行"错误

3 java android bitmap android-emulator

我正在尝试从中检索图像Uri,首先我从图库中选择了图像,然后使用意图传递了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();

            }
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误

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
Run Code Online (Sandbox Code Playgroud)

//一些额外的错误

 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
Run Code Online (Sandbox Code Playgroud)

你可以看到我有uri我的imgUri,不知道我做错了什么或失踪,如果有人知道什么是失踪,请纠正我谢谢:)

我使用genyMotion模拟器是问题的原因吗?

Vya*_*lav 5

将此权限附加到您的AndroidManifest.xml文件中

 <uses-permission 
        android:name="android.permission.READ_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)

并使用

Uri imgUri = Uri.parse("file://"+getIntent().getExtras().getString("imageUri"));