androidonactivityresultucrop

Ucrop onActivityMethod not working


I used below code from ucrop library and crop window is showing up.

 Uri destinationUri = Uri.fromFile(new File(myContext.getCacheDir(), "IMG_" + System.currentTimeMillis()));
            UCrop.of(sourceUri, destinationUri)
                     .withMaxResultSize(maxWidth, maxHeight)
                    .start(myContext);

but, control is not going inside onActivityResult method. If/Else both not working.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
        final Uri resultUri = UCrop.getOutput(data);
    } else if (resultCode == UCrop.RESULT_ERROR) {
        final Throwable cropError = UCrop.getError(data);
    }
}

Any idea whats wrong, did I missed something?


Solution

  • Uri destinationUri = Uri.fromFile(new File(myContext.getCacheDir(), "IMG_" + System.currentTimeMillis()));
                    UCrop.of(sourceUri, destinationUri)
                    .withMaxResultSize(1080, 768) // any resolution you want
                    .start(mContext, YourFragment/YourActivity.this);