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

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

Open
kapparapukeerthana opened this issue Apr 18, 2024 · 2 comments

Comments

@kapparapukeerthana
Copy link

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
Copy link

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
Copy link
Author

kapparapukeerthana commented Jun 26, 2024

I have found a workaround for this.

private async Task<ICameraInternal?> GetCameraPreview(CameraBarcodeReaderView cameraBarcodeReaderView)
{
var status = await Permissions.CheckStatusAsync<Permissions.Camera>();
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.

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