0

My code ia as below.

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

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
     grantUriPermission(getPackageName(),mImageCaptureUri,Intent.FLAG_GRANT_READ_URI_PERMISSION);
     grantUriPermission(getPackageName(),mImageCropUri,Intent.FLAG_GRANT_READ_URI_PERMISSION);
     intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
    intent.putExtra("outputX", 480);
    intent.putExtra("outputY", 480);
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);

    intent.putExtra("scale", true);
    intent.putExtra("scaleUpIfNeeded", true);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCropUri);

              intent.putExtra("crop", "true");
              intent.putExtra("return-data", false);
              intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
              intent.putExtra("noFaceDetection", true);

try {
      startActivityForResult(intent, CROP_FROM_CAMERA);
    }
    catch (Exception e) {
                e.printStackTrace();
    }
  1. The test environment is AVD(API Level 31). It should have a default crop app, Google Photo. And my code about taking photo works fine.

  2. When running my app, I select a .jpg file from Downloads folder, and then call intent camera.action.CROP). But the code doesn't take effect at all.

  3. I checked the two uri in logcat,

mImageCaptureUri = content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F71/ORIGINAL/NONE/image%2Fpng/1987893059

mImageCropUri = content://com.myapp.fileprovider/my_pic/Pictures/tmp_kuilimar_16712596169354514375851720661420.jpg

In addition, I can't get any exception message in LogCat with e.printStackTrace().

So, what's wrong? ...... Thank you all in advance.

Johnson
  • 157
  • 3
  • 17

2 Answers2

0

Android does not have a CROP Intent.

It should have a default crop app, Google Photo

There is no requirement for any device, let alone any user of any device, to have an app that supports your undocumented and unsupported Intent action. And there is no requirement for Google Photo, or any other particular app, to support that undocumented and unsupported Intent action.

There are many image cropping libraries available for Android. Please use one.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Probably got it from [this answer](https://stackoverflow.com/a/27294293/9473786), which has enough upvotes to suggest that it at least sometimes works (or used to). – Tyler V Dec 17 '22 at 13:49
0

I found that the issue resulted from the grantUriPermission(). We should grant Uri Permission to Google Photo, which will preform CROP, other than the app self. Thank you all.

Johnson
  • 157
  • 3
  • 17