How to find and use the required Intent/Activity

While implementing capturing and cropping a photo I was getting frustrated. On my Galaxy Note 2 (4.4.2) the behaviour was different compared to the Genymotion Simulator of the Note 2 (4.3). Then I discovered by accident that in the contacts app on the simulator cropping works. So I began to search which Activity this could be to find out how to set the parameter. I already know that the Action com.android.camera.action.CROP has to be used.

With the help of the Android Debug Bridge (adb)

adb shell dumpsys package > d:\test.txt

I can pipe system information of the connected device into a file. For more information about the Android Debug Bridge visit the official documentation. There for the sumulated Note 2 I got

....
MIME Typed Actions:
  android.intent.action.DIAL:
    52a70a98 com.android.contacts/.NonPhoneActivity filter 52a70b2c
    52a6ce48 com.android.dialer/.DialtactsActivity filter 52a2c644
  com.android.camera.action.CROP:
    52a86a2c com.android.gallery/com.android.camera.CropImage filter 52a86b98
  android.intent.action.SEARCH:
...

which lists com.android.camera.CropImage as an Activity which can crop an image.

For the real Note 2 I got

...
com.android.camera.action.CROP:
    42eaaeb0 com.sec.android.gallery3d/.app.CropImage filter 42eab990
    42738108 com.google.android.apps.plus/com.google.android.apps.photoeditor.fragments.PlusCropActivity filter 42cfedd8
...

But how to call that via an Intent? One can look into the code of CropImage via e.g. Grepcode (search for CropImage and choose the 4.3 version) to see how to set the parameter of the Intent.

Another approach is to search for com.android.camera.action.CROP on e.g. GrepCode via site:grepcode.com "com.android.camera.action.CROP" on google. This will list some constant definitions but also e.g. com.android.camera.Camera which defines the Intent via the action “com.android.camera.action.CROP”`. Here we can see how to set the parameter of the Intent.

But as a lot of sources in the web correctly state, there is no build in crop Intent on all Android devices. See e.g. The CommonsBlog. So be careful when using com.android.camera.action.CROP. Use a cropping library or provide a fallback when no cropping Activity is found.

Die Kommentarfunktion ist geschlossen.