uCrop icon indicating copy to clipboard operation
uCrop copied to clipboard

Result callback not called in onActivityResult

Open bittentech opened this issue 6 years ago • 4 comments

I am testing the library on Android Oreo 8.1.0. I am calling the UCrop start() method after choosing an image from the gallery in onActivtyResult(). But after I finish cropping the image by clicking the right tick, nothing happens, the activity just finishes, onAcitivtyResult() is not being called. Here is my code: @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { filePath = data.getData(); Toast.makeText(getContext(),"Image selected.", Toast.LENGTH_SHORT).show(); cropImage(); } else if (resultCode == RESULT_OK && requestCode == 1) { filePath = UCrop.getOutput(data); Toast.makeText(getContext(),"Image cropped.", Toast.LENGTH_SHORT).show(); } else if (resultCode == UCrop.RESULT_ERROR) { final Throwable cropError = UCrop.getError(data); Toast.makeText(getContext(),"Error: "+cropError, Toast.LENGTH_SHORT).show(); } } private void cropImage() { UCrop.of(filePath, filePath) .withAspectRatio(16, 16) .withMaxResultSize(500, 500) .start(getActivity(),1); }

bittentech avatar Nov 16 '18 11:11 bittentech

From your code it seems that you're calling it from within a Fragment. In which case you need to use the start() function that takes a context, the fragment and the request code:

public void start(@NonNull Context context, @NonNull androidx.fragment.app.Fragment fragment, int requestCode)

BapediBoupi avatar Jan 07 '19 17:01 BapediBoupi

I am also facing the same issue in Oreo OS. Can anybody resolve the issue?

cyberformed avatar Jan 11 '19 06:01 cyberformed

please refer to 335

programmerpinggiran avatar Jan 20 '19 02:01 programmerpinggiran

I had to pass context and fragment so this is how I did in kotlin

UCrop.of(sourceFile.toUri(), destinationFile.toUri())
    .withAspectRatio(1.toFloat(), 1.toFloat())
    .start(requireContext(), this)

zohabAli avatar Mar 03 '21 07:03 zohabAli