Ucrop onActivityMethod not working

泪湿孤枕 提交于 2019-12-25 08:28:12

问题


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?


回答1:


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);



回答2:


Changing calling code to below works.

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


来源:https://stackoverflow.com/questions/41476946/ucrop-onactivitymethod-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!