“resolveUri在错误的位图uri上失败:content:// media / external / images / media / 49644”我无法查看图像

时间:2015-01-30 17:44:16

标签: java android bitmap

你好,我是开发Android应用程序的初学者。我一直在做一个联系人应用程序。 这是我的java代码,从库中选择图像后我无法在我的gui上显示图像。 我已经在ANDROID KITKAT测试了它的显示图像。 但是这个代码在ANDROID ICECREAM SANDWICH上成功运行,它在从画廊中选择后显示图像。

contactimageview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
    Intent intent= new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent,"select image"),1);
   }
});
}

public void onActivityResult(int reqCode,int resCode,Intent data) {
    if (resCode == RESULT_OK) {
        if (reqCode==1){
            imageUri = data.getData();
            contactimageview.setImageURI(data.getData());
      }}
      }

选择图像后,我得到以下日志,如下所示 我认为onActivityResult方法代码存在问题。

 01-30 23:04:04.271  30813-30813/com.example.dell4.contact W/ResolverActivity﹕            mLaunchedFromPackage=com.example.dell4.contact
01-30 23:04:04.606  30813-30813/com.example.dell4.contact D/AbsListView﹕ Get MotionRecognitionManager
01-30 23:04:04.706  30813-30813/com.example.dell4.contact D/dalvikvm﹕ GC_FOR_ALLOC freed 144K, 9% free 13792K/15016K, paused 13ms, total 13ms
01-30 23:04:06.711  30813-30813/com.example.dell4.contact W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection
01-30 23:04:06.991  30813-30813/com.example.dell4.contact D/AbsListView﹕ onDetachedFromWindow
01-30 23:04:12.641  30813-30813/com.example.dell4.contact W/ImageView﹕ Unable to open content: content://media/external/images/media/49644
    java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/49644 from pid=30813, uid=10020 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
            at android.os.Parcel.readException(Parcel.java:1465)
            at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
            at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:148)
            at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:682)
            at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1067)
            at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:907)
            at android.content.ContentResolver.openInputStream(ContentResolver.java:632)
            at android.widget.ImageView.resolveUri(ImageView.java:674)
            at android.widget.ImageView.setImageURI(ImageView.java:409)
            at com.example.dell4.contact.MainActivity.onActivityResult(MainActivity.java:94)
            at android.app.Activity.dispatchActivityResult(Activity.java:5643)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3677)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3724)
            at android.app.ActivityThread.access$1400(ActivityThread.java:175)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5602)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)
01-30 23:04:12.641  30813-30813/com.example.dell4.contact I/System.out﹕ resolveUri failed on bad bitmap uri: content://media/external/images/media/49644

1 个答案:

答案 0 :(得分:3)

您需要将权限<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>添加到清单文件中。