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();
}
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.
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.
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.