Question

I want to take a picture with the camera and crop it. This works great (with the second code) on newer devices with this code I found on the community wiki:

Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.android.gallery", "com.android.camera.CropImage");

On some Android versions, including the newest, com.android.gallery doesn't exist anymore. You need to use this then:

Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.google.android.gallery3d", "com.android.gallery3d.app.CropImage");

Of course I want to support older devices too. What is meant with "some Android versions"? Can someone give me an API level? Or are there any final constances in the Android source which I can use to select the correct Strings for the intent?

Was it helpful?

Solution 2

I found a better code for this problem. This here will search for apps which are able to crop images and start the first that is found. Hope that help someone.

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

List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(cropApps, 0);
int size = list.size();

if (size == 0) 
{           
    Toast.makeText(context, "Can not find image crop app", Toast.LENGTH_SHORT).show();      
    return null;
} 
else 
{
    ResolveInfo res = list.get(0);

    Intent intent = new Intent();
    intent.setClassName(res.activityInfo.packageName, res.activityInfo.name);

    intent.setData(imageCaptureUri);
    intent.putExtra("outputX", 96);
    intent.putExtra("outputY", 96);
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);

    startActivityForResult(intent, CROP_FROM_CAMERA);
}

OTHER TIPS

Some devices don't support cropping, meaning that their gallery application does not have it built it. The best solution is building a cropping mechanism into your app. Here is a good open source cropper:

https://github.com/edmodo/cropper

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top