journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder
https://journeyapps.com/
Apache License 2.0
5.68k stars 1.26k forks source link

Enable Torch without going Androidx #716

Closed sengsational closed 1 year ago

sengsational commented 1 year ago

I've been using this configuration:

implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
implementation 'com.google.zxing:core:3.3.2'

And when I tried the next release (4 dot), I got the Didn't find class "androidx.core.content.ContextCompat" error. I'm not in a position to switch to androidx with this project right now, but would like to give the user the ability to turn on the torch.

From November of 2018, I see #406 [https://github.com/journeyapps/zxing-android-embedded/commit/a4dfc2fca431696302c4d2d6ef90532bc9d4a68d] which looks like it should be available because 3.6.0 is dated September of 2019.

But when I look at IntentIntegrator 3.6.0 source, I don't see setTorchEnabled() is there.

What's the easiest way to get the torch working without going to androidx?

            IntentIntegrator integrator = new IntentIntegrator(this);
            integrator.addExtra("TORCH_ENABLED", true); // Doesn't work
            integrator.setPrompt("Scan the Touchless Menu QR code");
            integrator.setTimeout(8000);
            integrator.setOrientationLocked(true);
            //integrator.setTorchEnabled(true); // Doesn't compile in 3.6.0
            integrator.initiateScan();
sengsational commented 1 year ago

Never mind. I've braved the androidx refactoring and lived through it.