capacitor-community / barcode-scanner

A fast and efficient (QR) barcode scanner for Capacitor
MIT License
437 stars 169 forks source link

The UI doesn't show up in Android 8.1 (light mode, Capacitor 6, Ionic 4, Angular 14, WebView 70) #156

Closed salazarbarrera closed 2 years ago

salazarbarrera commented 2 years ago

Describe the bug I can't find the scanner in the DOM. I followed the advice to manually hide certain objects as it was suggested by other users but it didn't work. I also tried to start BarcodeScanner from app.component.ts, unsuccessfully.

You can see an example project here.

To Reproduce

  1. Clone the example repo above (this one)
  2. Connect the device, execute $ ionic cap run android and select the target device. Alternatively you can compile, install and run it with Android Studio after executing $ ionic cap add android.
  3. After seeing the splash screen, you will see the "...Scanner Interface" div I added below the body div, but no scanner will appear, neither visually nor in the DOM.

Expected behavior At least the BarcodeScanner should appear in the DOM.

Version v3.0.0

Smartphone

salazarbarrera commented 2 years ago

The same code was tested in a vanilla Android 11 (Nokia 7.2 up to date, light mode) with WebView 104.0.5112.97.

Same results.

thegnuu commented 2 years ago

@salazarbarrera you are not requesting permission to the camera. Without camera permission the plugin will never be able to display something ;)

Check the docs for permission "best-practice-stuff", the easiest way for testing is to add await BarcodeScanner.checkPermission({ force: true }); before calling await BarcodeScanner.startScan(), but you should implement better checks based on the state of course :)

After adding the check it worked without any issues on my device.

salazarbarrera commented 2 years ago

Oooh, I thought it was enough to declare the camera permission in the manifest, I didn't notice that part.

This solves the issue. I'll fix and complete my example and let it stay among my repos so others can use it in case they find this issue via search engines. Thanks for your help.

Before I close the the issue, and knowing this is getting off-topic, should BarcodeScanner.enableTorch() turn on the flashlight? It changes the state shown by getTorchState(), but it doesn't seem to do anything yet (despite this PR #78).

thegnuu commented 2 years ago

It should yes, and at least on my device it does so as well...

Unfortunately I have no other device to test it with, but on my android and iOS devices it works as expected :)

salazarbarrera commented 2 years ago

I'll open another issue about that when I modify the code after work. About this matter, the problem is solved.