Security exception when opening image via Intent.ACTION_VIEW. lollipop

In my application, I have a list box with images selected from the standard android firepicker (lollipop) Each image has a URI, for example the content: //com.android.providers.media.documents/document/image%3A105628.

Code for selecting an image:

 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 the image in the header of the list with ACTION_VIEW activated. And view apps with error.

Code to view the image:

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

      

An 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 a granted permission from my application to another application (viewer)?

PS: I've seen this workaround. Android KitKat securityException when trying to read from MediaStore

+3


source to share


3 answers


And the answer adds this flag intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

to the ACTION_VIEW intent



+3


source


You have to 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: fooobar.com/questions/379830 / ...

PS Did the answer to the Security Kit for Android KitKat query help you?

0


source


You have to 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);

      

0


source







All Articles