3

In my app I have a list with images chosen from standart android (lollipop) filepicker. Each image have URI like content://com.android.providers.media.documents/document/image%3A105628.

Code for image selection:

 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
 intent.addCategory(Intent.CATEGORY_OPENABLE);
 intent.setType("image/*");
 startActivityForResult(intent, SELECT_IMAGE_ACTIVITY_REQUEST_CODE);

By clicking on image in list intent with ACTION_VIEW invoked. And view app crashes with exception.

Code for image view:

Intent viewIntent = new Intent(Intent.ACTION_VIEW);
viewIntent.setDataAndType(finalPhoto, "image/*");
startActivity(viewIntent);

Exception:

java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{247dd26c 18416:com.google.android.apps.plus/u0a51} (pid=18416, uid=10051) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
            at android.os.Parcel.readException(Parcel.java:1540)
            at android.os.Parcel.readException(Parcel.java:1493)
            at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3267)
            at android.app.ActivityThread.acquireProvider(ActivityThread.java:4589)
            at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2439)
            at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1442)
            at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1064)
            at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:921)
            at android.content.ContentResolver.openInputStream(ContentResolver.java:646)
            at jcq.a(PG:129)
            at dcv.f(PG:28)
            at dcv.j(PG:16)
            at hxz.d(PG:40)
            at df.e(PG:242)
            at dg.a(PG:51)
            at dg.c(PG:40)
            at dx.call(PG:123)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)

I read about SAF, is it possible to delegate granted permission from my app to another app (viewer)?

PS: I saw this workaround. Android KitKat securityException when trying to read from MediaStore

Kolchuga
  • 716
  • 6
  • 17

3 Answers3

3

And the answer is add this flag intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); to ACTION_VIEW intent

Kolchuga
  • 716
  • 6
  • 17
0

You should add this to your Manifest:

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

After that it should work


Edit

Perhaps you can take a look at this answer: https://stackoverflow.com/a/20382826/2767703

P.S. Didn't the Android KitKat securityException answer help you?

Community
  • 1
  • 1
Kevin van Mierlo
  • 9,554
  • 5
  • 44
  • 76
0

You should add this to your Manifest:

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

Use this code for openGallery

    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, REQUEST_CODE_GALLERY);
Amitabha Biswas
  • 3,281
  • 1
  • 11
  • 23