I am trying to create a simple application that can get an image from the Gallery application and display it on the imageButton button. I am testing API 21 on a phone running Android 5.0.1. Unfortunately, no matter what I try, I get a security error - even when I specify permissions.
My code for getting the image:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent){ super.onActivityResult(requestCode, resultCode, imageReturnedIntent); switch(requestCode){ case PICK_IMAGE_REQUEST: if(resultCode == RESULT_OK && imageReturnedIntent != null && imageReturnedIntent.getData() != null) { Uri uri = imageReturnedIntent.getData(); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
The code works when I try to select an image from Dropbox, but when I select an image from the gallery, I get
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/35634 from pid=25240, uid=10070 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
I made a usage permission tag for the READ_EXTERNAL_STORAGE child of the manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="[REDACTED]"> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" /> <uses-permission tools:node="replace" android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="18" /> <application> [REDACTED] </application> </manifest>
I searched high and low on other posts, but still can't figure out why I am still getting this nasty error.
java android android-5.0-lollipop android-permissions android-gallery
Zheryu Sep 02 '15 at 10:38 2015-09-02 10:38
source share