Redth / ZXing.Net.Maui

Barcode Scanning for MAUI?
MIT License
478 stars 153 forks source link

Laser Scan is not working after triggering Zxing CameraBarcodeReaderView. #181

Open kapparapukeerthana opened 7 months ago

kapparapukeerthana commented 7 months ago

I am using the CameraBarcodeReaderView(Zxing) in my xaml for barcodesDetected. We also use laser scan for scanning. Laser scan is working until the zxing is triggered. Once zxing is used, laser scan stopped working.
I used unloaded event to disconnect the handler, but it is not working even then.

barcodeReader?.Handler?.DisconnectHandler();

Please provide any workaround for this. Thanks in advance

cakmak-serkan commented 4 months ago

I am having same issue to resolve.

workaround For mobile users render generate CameraBarcodeReaderView for laser scanner (MUNBYN) just display Entry than focus()

Exception is: [monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Camera.Core.dll [monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Camera.Lifecycle.dll [monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.Google.Guava.ListenableFuture.dll [CameraManagerGlobal] Connecting to camera service [CameraRepository] Added camera: 0 [Camera2CameraInfo] Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_3 [CameraValidator] Verifying camera lens facing on C66, lensFacingInteger: null [CameraValidator] Camera LensFacing verification failed, existing cameras: [Camera@4a30e7e[id=0]] [CameraX] Retry init. Start time 695539612 current time 695539675 [CameraX] androidx.camera.core.impl.CameraValidator$CameraIdListIncorrectException: Expected camera missing from device. [CameraX] at androidx.camera.core.impl.CameraValidator.validateCameras(CameraValidator.java:97) [CameraX] at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2$androidx-camera-core-CameraX(CameraX.java:342) [CameraX] at androidx.camera.core.CameraX$$ExternalSyntheticLambda3.run(Unknown Source:10) [CameraX] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) [CameraX] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) [CameraX] at java.lang.Thread.run(Thread.java:923) [CameraX] Caused by: java.lang.IllegalArgumentException: No available camera can be found [CameraX] at androidx.camera.core.CameraSelector.select(CameraSelector.java:82) [CameraX] at androidx.camera.core.impl.CameraValidator.validateCameras(CameraValidator.java:91)

kapparapukeerthana commented 4 months ago

I have found a workaround for this.

private async Task<ICameraInternal?> GetCameraPreview(CameraBarcodeReaderView cameraBarcodeReaderView) { var status = await Permissions.CheckStatusAsync(); if (status == PermissionStatus.Denied) return null; var bindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance; var strongHandlerProperty = typeof(CameraBarcodeReaderView).GetProperty("StrongHandler", bindingFlags); var cameraBarcodeReaderViewHandler = strongHandlerProperty.GetValue(cameraBarcodeReaderView) as CameraBarcodeReaderViewHandler; var manageField = typeof(CameraBarcodeReaderViewHandler).GetField("cameraManager", bindingFlags); var cameraManager = manageField.GetValue(cameraBarcodeReaderViewHandler); var cameraPreviewField = typeof(CameraBarcodeReaderViewHandler).Assembly.GetType("ZXing.Net.Maui.CameraManager").GetField("cameraPreview", bindingFlags); var preview = cameraPreviewField.GetValue(cameraManager) as Preview; return preview.Camera; }

You can call the above method in ondisappearing like "GetCameraPreview(barcodeReader).Result.Close(); " I used close here because release would never reinitialize the camera again.

This will work in all scenarios except one scenario. If we use camera to scan and lock the screen and unlock it then laser stopped working. I have to kill the app or open the camera and then laser started working. I am yet to find the reason and solution for this scenario. Hope this would help you.