Reputation: 11
hello I'm a beginner in developing android apps.I've been doin a contacts app. This is my java code where im unable to display image on my gui after selecting image from gallery. Ive tested in ANDROID KITKAT IT DOESNT SHOW IMAGE. But this code works successfully on ANDROID ICECREAM SANDWICH,IT DISPLAYS IMAGE AFTER CHOOSING FROM gallery.
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());
}}
}
after i select the image i get the following log as below I think there is a problem in onActivityResult method code.
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
Upvotes: 1
Views: 2909
Reputation: 2764
You need to add the permission <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
to your manifest file.
Upvotes: 3