SocketMobile / capture_maui_sdk_sample

0 stars 0 forks source link

Device will never scan barcode with this sample #2

Closed chrisbrasington closed 1 year ago

chrisbrasington commented 1 year ago

I'm running this app unaltered with the Socket Mobile Companion app running in the background displaying App Mode. I am using device S860. I am running with visual studio 2022 for local android device usb debugging (not emulator).

The app will always trigger event for Device Arrival.

On scan of a barcode it will vibrate but never trigger DecodedData at all. Sometimes the event will trigger once and never again

As you can image this makes the device functionally unusable. Please assist as this is reproducible with this code sample directly.

chrisbrasington commented 1 year ago

Device is set to android/windows application mode

chrisbrasington commented 1 year ago

Is the companion app interfering? It seems better behaved with it not running. (still reproducible)

chrisbrasington commented 1 year ago

After spending some time with your SocketMobile.Capture, I've learned how to better avoid my issue of missing events.

One, I ensured my scanner usage was a singleton ideally opening for the entire session of my app rather than opening/closing multiple times.

Two, I tapped into .NET MAUI App Lifecycle events for android because this sample does not call CloseAsync() and the app stopping/pausing was a bit unstable. If you run capture_maui_sdk_sample twice this is when you can see DeviceArrival but not DecodedData nor DeviceRemoval. I suspect Close is necessity or at least helpful to a clean open. Having OpenAsync fire DeviceArrival but no other events does feel like a bug I had to work-around, but my using lifecycle events, it is an occurrence that no longer occurs.

Three, because I couldn't rely on the accuracy of DeviceArrival meaning the scan would fire an event, I switched to reading the battery status as I found this always accurate. In a bad state (disconnected or failing), it will either return with "Error -32" or thrown an exception, which I can interpret as "Disconnected". Typically either restarting the app or power cycling the scanner fixes this.

All that said, I am happy to have a stable app and consistent behavior with this scanner in a MAUI app.