Yalantis/uCrop

UCrop.getOutput returns the same uri

ErnestoDavidOlivaPerez opened this issue · 1 comments

I have this code

private void cropImage(Uri uri){
        UCrop.Options options = new UCrop.Options();
        options.setShowCropGrid(false);
        options.setHideBottomControls(true);
        options.setCircleDimmedLayer(true);
        options.withAspectRatio(100, 100);

        UCrop uCrop = UCrop.of(uri, Uri.fromFile(new File(getCacheDir(), "image.png")));

        uCrop.withOptions(options);
        launcherCrop.launch(uCrop.getIntent(this));
    }

private final ActivityResultLauncher<Intent> launcherCrop = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            new ActivityResultCallback<ActivityResult>() {
                @Override
                public void onActivityResult(ActivityResult result) {
                    if (result.getData() != null) {
                        Uri uri = UCrop.getOutput(result.getData());
                        image.setImageURI(uri);
                    }
                }
            });

this works perfectly the first time it is launched but when relaunching the intent the image does not change, I have tried everything, Picasso, FilesDir, png, jpg, another name for the file, even deleting the image.png file before creating it but nothing has worked the only thing that has worked for me is to create a counter and include it to the file name each time it is created.

UCrop uCrop = UCrop.of(uri, Uri.fromFile(new File(getCacheDir(), "image" + count++ + ".png")));

with this code it works perfectly but as you can imagine it is not very clean, any solution?
thank you in advance.

solved based on #223, I leave code of how to reset the imageView

image.setImageResource(android.R.color.transparent);
image.setImageURI(uri);