SecurityException when app try to use Google Photos to crop taken photo

539 views Asked by At

My app successfully take photo from camera then redirect user to a pop-up list which contains available apps that can crop the photo as below:

Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");

List<ResolveInfo> list = mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

When user select Google Photos option it gets this exception:

Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=66990, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/0/1/content://media/external/images/media/6519/ORIGINAL/NONE/2122203960 flg=0x1 launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F6519/ORIGINAL/NONE/2122203960} }} to activity {com.turkcell.android.ccsimobile/com.turkcell.android.ccsimobile.HomeActivity}: java.lang.SecurityException: Uid 10050 does not have permission to uri 0 @ content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F6519/ORIGINAL/NONE/2122203960
   at android.app.ActivityThread.deliverResults(ActivityThread.java:4472)
   at android.app.ActivityThread.handleSendResult(ActivityThread.java:4515)
   at android.app.ActivityThread.-wrap22(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6682)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by java.lang.SecurityException: Uid 10050 does not have permission to uri 0 @ content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F6519/ORIGINAL/NONE/2122203960
   at android.os.Parcel.readException(Parcel.java:1693)
   at android.os.Parcel.readException(Parcel.java:1646)
   at android.app.ActivityManagerProxy.grantUriPermission(ActivityManagerNative.java:5763)
   at android.app.ContextImpl.grantUriPermission(ContextImpl.java:1744)
   at android.content.ContextWrapper.grantUriPermission(ContextWrapper.java:764)

at this line:

getContext().grantUriPermission(packageName, mSelectedImage, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);

This line is used in a loop to give permission for every available app that shown for crop option:

    for (ResolveInfo res : list) {
        String packageName = res.activityInfo.packageName;
        getContext().grantUriPermission(packageName, mSelectedImage, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
           ... 
           ...   
    }

Exception says does not have permission but i've already used grantPermission() method for it.

Note: mSelectedImage is uri of photo that is taken by camera.

0

There are 0 answers