Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is com.android.camera.action.CROP not available for Android jelly bean 4.3?

Tags:

android

camera

I was using com.android.camera.action.CROP for cropping after taking pic using camera.

Below was my code which used to work earlier before 4.3.

Intent cropIntent = new Intent("com.android.camera.action.CROP");
                        cropIntent.setType("image/*");
                        cropIntent.putExtra("crop", "true");
                        cropIntent.putExtra("aspectX", 1);
                        cropIntent.putExtra("aspectY", 1);
                        cropIntent.putExtra("outputX", Conf.getInt("IMAGE_WIDTH"));
                        cropIntent.putExtra("outputY", Conf.getInt("IMAGE_HEIGHT"));
                        cropIntent.putExtras(extras);
                        startActivityForResult(cropIntent, CROP_REQUEST_CODE);

But now since android crop action takes you to gallery(because gallery is default with crop), this cropping method fails(photo is not saved to gallery).

Does any one knows a way out of this issue. Where I can use the crop on the photo taken from camera

like image 884
Himanshu Virmani Avatar asked Aug 02 '13 09:08

Himanshu Virmani


2 Answers

Copying the answer from a similar question asked earlier..

Have you considered just using a library like this one:

GitHubLink

I find the com.android.camera.action.CROP can sometimes behave differently from phone to phone and is not always available, so it could cause some problems for you anyway if you are looking to release it.

UPDATE:

I have tested the above library with Android 4.3 and it works with no problem. You just need to add the library to your project.

You can then write your method in a very similar way:

private void performCrop(Uri picUri) {
//you have to convert picUri to string and remove the "file://" to work as a path for this library
String path = picUri.toString().replaceAll("file://", "");
try {
    int aspectX = 750;
    int aspectY = 1011;

    Intent intent = new Intent(this, CropImage.class);
    //send the path to CropImage intent to get the photo you have just taken or selected from gallery
    intent.putExtra(CropImage.IMAGE_PATH, path);

    intent.putExtra(CropImage.SCALE, true);

    intent.putExtra("aspectX", aspectX);
    intent.putExtra("aspectY", aspectY);

    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCurrentPhotoPath)));

    startActivityForResult(intent, CROP);
}
catch (ActivityNotFoundException anfe) {
    String errorMessage = "Your device doesn't support the crop action!";
    Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
    toast.show();
}
like image 79
Himanshu Virmani Avatar answered Oct 16 '22 17:10

Himanshu Virmani


According to @commonsware 's post
This intent is based on AOSP camera app which may or may not be available in target device, for some 4.3 devices it may work while for some it wil not.

So better approach will be to use any open source library found at Android arsenal
(make sure they are also not based on AOSP).

like image 23
Darpan Avatar answered Oct 16 '22 17:10

Darpan