0

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.

charman
  • 123
  • 6
  • Android does not have a `CROP` `Intent`. There are many [image cropping libraries available for Android](https://android-arsenal.com/tag/45). Please use one. – CommonsWare Dec 14 '17 at 12:48
  • Ok let's say there is no CROP Intent in Android. But is this directly related to this issue? When i select the photo from my gallery, my app open google photos crop successfully. Btw of course i didn't test it with huge kind of devices. – charman Dec 14 '17 at 12:59
  • "But is this directly related to this issue?" -- insofar as you would not have the problem, then yes. – CommonsWare Dec 14 '17 at 13:10
  • I mean, there is no problem when photo is selected from gallery. Why? I think this issue is about something different. – charman Dec 15 '17 at 05:46
  • The "CROP Intent" is part of the Android Camera app, which does not have access to your private images location. You may try to improve the situation by writing an FileProvider. – Alex Cohn Oct 13 '18 at 13:37

0 Answers0