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