1

My app has the option of passing a ACTION_CAPTURE_IMAGE Intent to the Camera App post which I provide an option to crop the image with any available App that can crop it. Now, since Google Photos is being made available by default on many of the devices these days, it turns out that often Google Photos is the only App available for crop.

Now, there is no problem capturing or cropping images on API level <= 23 but with the API level 24, the security model of Android has made changes and now the we are not allowed to expose a file:// URI directly through an Intent. This has been discussed on SO too:

android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

The solution uses a ContentProvider and the solution works except now we talk in terms of content:// instead of file://

So, I am now sending a content:// URI to any available cropping App. Turns out, Google Photos is showing the Toast - "Editing not supported on this image". This is because of the inability of handling a content:// URI. Now, if some third party App doesn't handle a content:// URI and Android doesn't let me pass a file:// URI, how am I supposed to have the image cropped?


The code that sends the CROP request for reference:

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

List < ResolveInfo > list = getPackageManager().queryIntentActivities(
    intent, 0);

int size = list.size();

if (size == 0) {
    Toast.makeText(this, "Can not find image crop app",
        Toast.LENGTH_SHORT).show();
} else {
    //intent.setData(mImageCaptureUri);
    intent.setDataAndType(mImageCaptureUri, "image/*");

    intent.putExtra("crop", "true");
    intent.putExtra("outputX", 150);
    intent.putExtra("outputY", 150);
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    if (size == 1) {
        Intent i = new Intent(intent);
        ResolveInfo res = list.get(0);

        i.setComponent(new ComponentName(res.activityInfo.packageName,
            res.activityInfo.name));

        startActivityForResult(i, CROP_FROM_CAMERA);
    }

And here is the Logcat output:

09-01 15:57:19.588 2347-4568/system_process I/ActivityManager: Start proc 7045:com.google.android.apps.photos/u0a64 for activity com.google.android.apps.photos/.photoeditor.intents.EditActivity
09-01 15:57:19.630 6179-6260/com.snap.testsnapboard D/EGL_emulation: eglMakeCurrent: 0xa9005de0: ver 2 0 (tinfo 0xa9003780)
09-01 15:57:19.834 7045-7045/com.google.android.apps.photos W/System: ClassLoader referenced unknown path: /system/app/Photos/lib/x86
09-01 15:57:20.521 7045-7045/com.google.android.apps.photos W/TrustedPartners: no provider found for com.motorola.camera.provider.bestshotprovider.BestShotProvider; do not trust
09-01 15:57:20.522 7045-7045/com.google.android.apps.photos W/TrustedPartners: no provider found for com.google.android.apps.photos.api.SpecialTypesProvider; do not trust
09-01 15:57:20.522 7045-7045/com.google.android.apps.photos W/TrustedPartners: no provider found for com.lge.photos.specialtypeprovider; do not trust
Manish Kumar Sharma
  • 12,982
  • 9
  • 58
  • 105

1 Answers1

0

You should add an extra putExtra() to your intent.

The Google Fotos app does not want to change the original image but instead of telling so it cries

"Editing not supported on this image"

(Again an example of a bad message)

So indicate a path where the cropped image can be saved with:

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(this)));

Where getTempFile() delivers a File object for a -non existing or existing- file in a -non existing or existing- cache dir for instance.

The funny thing here is that you can supply a file:// path here on Android 7. Indeed funny.

greenapps
  • 11,154
  • 2
  • 16
  • 19
  • Okay. With your answer, the App is accepting the content:// URI but now its showing the message, "Cannot edit images smaller than 50x50 px". The output is certainly not less than 50x50. No idea, what could prompt this message. – Manish Kumar Sharma Sep 02 '17 at 03:52
  • It is about the input. Yes i saw that message also a few times yesterday when i was testing this code. Forgot what it was and no code at hand now. – greenapps Sep 02 '17 at 06:33
  • But then you have not commented on my suggestion to test and to select a file with ACTION_GET_CONTENT. – greenapps Sep 02 '17 at 06:46