Open bittentech opened 6 years ago
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)
I am also facing the same issue in Oreo OS. Can anybody resolve the issue?
please refer to 335
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)
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); }