【问题标题】:"No content provider execution " error while converting uri to Bitmap将 uri 转换为位图时出现“没有内容提供程序执行”错误
【发布时间】:2016-01-19 10:10:07
【问题描述】:

我正在尝试从 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();

            }

但我得到这个错误

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 模拟器,这是问题的原因吗?

【问题讨论】:

  • 您阅读过openInputStream 文档吗?
  • @pskink 不,我只是从类似的场景中采用它
  • 这样做你就会知道Uri schemas 支持什么
  • 对此一无所知:(这是什么?
  • errrr,什么是什么?见uri语法

标签: java android bitmap android-emulator


【解决方案1】:

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

 <uses-permission 
        android:name="android.permission.READ_EXTERNAL_STORAGE" />

并使用

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

【讨论】:

  • 嘿兄弟首先感谢您的回复,我按照您的建议尝试了,但我似乎没有工作仍然获得相同的输出
  • 我只需要在路径变量中添加“file://”即可。
  • 最好使用Uri mUri=Uri.fromFile(new File(yourpath));
【解决方案2】:

遇到了同样的问题,可能是因为你的模拟器改变了我的模拟器工作,我从 genymotion 转移到 blueStack 并且它工作不知道为什么会发生,你应该试一试

http://www.bluestacks.com/download.html

【讨论】:

  • 感谢这是我已经尝试过的 :D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-29
  • 2018-11-27
  • 1970-01-01
  • 2011-11-10
  • 2014-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多