Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading com.google.android.apps.photos.contentprovider.MediaContentProvider requires the provider be exported, or grantUriPermission()

I received this crash report from an Android 6.0.1 user:

STACK_TRACE=java.lang.SecurityException: Permission Denial: reading com.google.android.apps.photos.contentprovider.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F19181/ORIGINAL/NONE/443149508 from pid=18891, uid=10128 requires the provider be exported, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1620)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:692)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1104)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:942)
at android.content.ContentResolver.openInputStream(ContentResolver.java:662)
at fr.free.nrw.commons.upload.UploadService.uploadContribution(UploadService.java:176)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:114)
at fr.free.nrw.commons.upload.UploadService.handle(UploadService.java:27)
at fr.free.nrw.commons.HandlerService$ServiceHandler.handleMessage(HandlerService.java:19)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)

From looking around, it appears that this is related to the Google Photos permission, com.google.android.apps.photos.permission.GOOGLE_PHOTOS . I already have this permission in my manifest, but this user is running API 23, which requires runtime permissions.

Problem is, how do I call the runtime permission for this? I know how to do it for standard permissions as described at https://developer.android.com/training/permissions/requesting.html#perm-check , but when I try to do

ActivityCompat.requestPermissions(thisActivity,
                    new String[]{com.google.android.apps.photos.permission.GOOGLE_PHOTOS},

it does not compile.

What is the name of the permission that I need to request at runtime to be able to access an image from Google Photos?

like image 827
misaochan Avatar asked Jul 11 '16 07:07

misaochan


1 Answers

Actually, you don't need any permission. This is security exception.

That's simple condition: When you request to google photos app via intent ACTION_PICK, after your photo selection receive an permission from provider. If you process this code in another context, system will throw an security exception. Because another context is not authorized.

Your request code like this:

Intent galleryIntent = new Intent(Intent.ACTION_PICK);
galleryIntent.setType("image/*, video/*");
if (galleryIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(Intent.createChooser(galleryIntent, "Select File"), RESULT_CODE);
}

@bluemist's answer very explanatory: https://stackoverflow.com/a/30909105/1136117

like image 197
The Goat Avatar answered Mar 03 '23 10:03

The Goat