9

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?

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
misaochan
  • 890
  • 2
  • 8
  • 25

1 Answers1

6

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

Community
  • 1
  • 1
The Goat
  • 1,080
  • 13
  • 19
  • Hi @Singan Ergin, This is fine when we request the image from our application. What if the user shares the image from google photos? I am having issues with share image from Google photos and Whatsapp Images, Please let me know if you find any solutions. – Simon Chius Jul 26 '17 at 06:39
  • 1
    Hi @SimonChius, if you redirect from opened activity to another activity, your sharing authorization/permission have been lost . I recommed to you 2 solution: - Save the sharing content temporary on your memory and use another activites - if you able to don't kill your authorized activity, reference the activity context from another activites. – The Goat Jul 26 '17 at 11:41
  • Thanks @Singan Ergin, I will try that. – Simon Chius Jul 27 '17 at 14:23