9

I found a lot of questions for how to crop an image. But, is there a way to start the edit image activity through an intent. I tried with com.android.camera.action.EDIT but it's not working. What I want to do is when I click on a button, start the activity for editing the image, like the one on the picture below:

enter image description here

It's like when I open an image from the gallery and click Edit from the menu.

nikmin
  • 1,803
  • 3
  • 28
  • 46

2 Answers2

17
Intent editIntent = new Intent(Intent.ACTION_EDIT);
editIntent.setDataAndType(uri, "image/*");
editIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(editIntent, null));
Darren Hinderer
  • 418
  • 1
  • 6
  • 12
  • 5
    You should add some explanations to your answer! – Alexandre Lavoie May 30 '13 at 22:59
  • If you `startActivityForResult()` then there are three possible outcomes of the Image Editor. Either the user edits the image and the resultCode is `Activity.RESULT_OK` , the user does not make any edits and clicks either `Done` or `Save`, depending on the editor which returns a resultCode of `Activity.RESULT_CANCELED` , or the user presses the back button which returns of resultCode of `Activity.RESULT_CANCELED`. Why is it that these last two options return the same resultCode value? And how can you differentiate the two? – Etienne Lawlor Jun 18 '14 at 15:39
  • @toobsco42 In my case, somehow, user can only press "save" without any other action that triggers `Activity.RESULT_OK`. How did manage that? Is there any other parameter that I should set when calling the intent? – Yusril Maulidan Raji Sep 23 '19 at 08:27
  • Show to me "no app can perform this action" – luke cross Jul 25 '20 at 14:02
2
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(yourimageuri, "image/*");
        intent.putExtra("crop", "true");
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("outputX", 640);
        intent.putExtra("outputY", 640);
        intent.putExtra("scale", true);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outPath);
        intent.putExtra("return-data", false);
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        intent.putExtra("noFaceDetection", true);
        startActivityForResult(intent, CAMERA_CROP_RESULT);
Jiang Qi
  • 4,450
  • 3
  • 19
  • 19
  • 2
    This is used only for cropping the image. I want all editing options like on the picture above – nikmin Mar 29 '13 at 07:45
  • try com.android.camera.action.EDITOR_CROP – Jiang Qi Mar 29 '13 at 07:50
  • You can browser android 4.2 gallery's AndroidManifest.xml https://android.googlesource.com/platform/packages/apps/Gallery2/+/android-cts-4.2_r2/AndroidManifest.xml ,search "com.android.camera.action" – Jiang Qi Mar 29 '13 at 07:50
  • `EDITOR_CROP` is something that I'm looking for. Is there a way to start it, but not to start the cropping. Just start the editor and let the user choose what he wants to do. I tried removing `intent.putExtra("crop", "true");` but it's not working. And another question: Will this work on android 3.2 because my app should support 3.2+ – nikmin Mar 29 '13 at 08:00
  • I am trying this example. I tried using same path as input file and output file, but it didn't overwrite the changes, instead created a new modified file with filename like IMG_xxx_xxx.jpg and also deleted input file. I simply want to crop image and save it back with same filename. – Adnan Nov 01 '14 at 13:24
  • @nikmin If you want all of the options, I think it's just `Intent intent = new Intent(Intent.ACTION_EDIT)` – John61590 Nov 09 '16 at 22:16