Question

I'm trying to crop an image from the media gallery. I'm able to access the image, start the default crop tool and even save the cropped image result.

However, the intent I'm using just will not return any results if the cropping was successful.

My MAIN Method:

// Crop photo intent.
Intent intent = new Intent("com.android.camera.action.CROP", null);         
intent.setData(uri);   
intent.putExtra("outputX", outputX);
intent.putExtra("outputY", outputY);
intent.putExtra("aspectX", aspectX);
intent.putExtra("aspectY", aspectY);
intent.putExtra("scale", scale);
intent.putExtra("return-data", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, createTempCroppedImageFile());
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

// Publish intent to crop picture.
activity.startActivityForResult(intent, activity.CROP_PHOTO_REQUEST_CODE);  

– OnActivityResult() Method –

// Photo crop activity.
if (requestCode == CROP_PHOTO_REQUEST_CODE) {
    if (resultCode == RESULT_OK) {
        Log.d(TAG, "user cropped a photo");
        signupScreen.setImage(new PhotoTool(this).getTempCroppedImageFileLocation());
    } else
        Log.d(TAG, "user cancelled photo crop");
}

If I cancel out of the crop activity, I get the "user cancelled photo crop" message successfully. But if I crop an image, the new cropped image will appear in the target directory but the OnActivityResult() function never ever gets called. What gives?

Looking at the LogCat, I'm finding that every time I save the cropped image, "JavaBinder" complains "Failed Binder Transaction". I understand this is somehow related to memory, but the cropped file is only 24KB in size.

Was it helpful?

Solution

Found the problem to this issue. It's unfortunately an Android limitation.

See Android cropper cannot go beyond 256?

I had set the output of my cropped image to 400x400. Unfortunately Android's default cropper can only do 256x256. This is so utterly frustrating, especially when there's no documentation on limits.

OTHER TIPS

Are you calling setResult(int) (link) in the crop intent?

UPDATE:\

Sending RESULT_CANCELLED is the default. It will always be sent back unless you implement a few things.

In your crop intent, when you have the finished the editing (i.e. the user taps the done button, or something similar), part of that process would call setResult(RESULT_OK).

example:

public void doneBTNPressed( View view ) {
    if ( view.getId() == R.id.doneBTN ) {
        this.isCropped = true;
    }
}

@Override    
protected void onPause() {
        if ( this.isCropped ) {
            setResult(RESUL_OK);
        }
        super.onPause();
    }

That result (RESULT_OK, plus another integer you specify) gets passed back to the calling Activity (assuming startActivityForResult() was used). There also a few overrides, depending on your needs. In the calling (parent) activity, you would have to implelement onActivityResultint,int,Intent) to get the result from the exiting activity.

In the link provided above, there is a section titled "Starting Activities and Getting Results," which explains the multiple ways to get information out of an exiting actvity.

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