Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black images on Android 13 #873

Open
TeamRainless opened this issue Feb 1, 2023 · 3 comments
Open

Black images on Android 13 #873

TeamRainless opened this issue Feb 1, 2023 · 3 comments

Comments

@TeamRainless
Copy link

Do you want to request a feature or report a bug?

report a bug

What is the current behavior?

Since updating to Android 13, seemingly randomly, images will appear completely black after upload. Sometimes uCrop simply crashes. I suspect this is because of "startactivityForResult" being deprecated and all the insane hurdles everyone has had to go through in order to get uCrop to work without it. I suspect it might've been completely removed from 13.

What is the expected behavior?

Not black image.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

Here's my solution to get uCrop running:

ActivityResultLauncher<Intent> ucropActivityIntent = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            new ActivityResultCallback<ActivityResult>() {
                public void onActivityResult(ActivityResult result) {
                    if (result.getData() != null && result.getResultCode() == RESULT_OK) {

                        Uri selectedUri = result.getData().getData();
                        String selectedUri2 = result.getData().getData().getPath();
                        getMimeType(getApplicationContext(), selectedUri);
                        
                        startCropActivity(selectedUri);

                    }
                }
            });

Please attach any image files, URL and stack trace that can be used to reproduce the bug.

Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop?

Latest uCrop and the Latest API.

@jens-muenker
Copy link

I guess nobody with write access updates this library anymore. (#651 (comment))

I made a fork which is working well for Android 13. In addition to the small updates, I translated most of the code to kotlin.

@TeamRainless
Copy link
Author

TeamRainless commented Feb 8, 2023

I guess nobody with write access updates this library anymore. (#651 (comment))

I made a fork which is working well for Android 13. In addition to the small updates, I translated most of the code to kotlin.

Excellent! And thanks for the reply. Do you have an example on implementation? I mean you say it works like uCrop in the ReadMe... but it obviously can't if you're using ActivityForResult now...

EDIT2: It actually looks like it's still using "startActivityForResult" in the example from a week ago...

@jens-muenker
Copy link

jens-muenker commented Feb 8, 2023

Yes you're right, ActivityForResult still exists, but I added the option to pass an ActivityResultLauncher to the start function. I wrote the following function in my personal project to use uCrop:

fun startCrop(uri: Uri, aspectRatio: AspectRatio, context: Context, activityResultLauncher: ActivityResultLauncher<Intent>) {

        Files.createDirectories(File(context.cacheDir.toString() + "/createRecipeTempImages/").toPath())

        var uCrop = of(uri, Uri.fromFile(File(context.cacheDir.toString() + "/createRecipeTempImages/",  currentTimeMillis().toString() + ".jpg")))
        //var uCrop = of(uri, Uri.fromFile(File(context.cacheDir, UriUtils.instance.getFileNameWithoutEndingFromUri(context, uri) + ".jpg")))
        uCrop = uCrop.withAspectRatio(aspectRatio.aspectRatioX, aspectRatio.aspectRatioY)

        uCrop.start(context, activityResultLauncher)
    }

I hope this helps and I would improve the documentation with examples in the next weeks.
I know there still exist some things which are marked as deprecated. I plan to replace these in the future.

If you have any questions left, feel free to ask me anytime :)

EDIT: I added an example to the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants