Android Code Snippet Using a USB wired Barcode scanner

I've recently needed to create an App that uses a wired barcode scanner as part a Kiosk-style application in a public library. I wasn't sure what hardware might work with the Nexus tables that I wanted to use.

I'm pleased to report that I've got the following combination working:

  • Nexus 7 (2012) Tablet
  • Zebra LS1203 Laser BarCode Scanner USB Kit with Stand

Some notes on this:

  • Powering the tablet and the scanner is a key issue

I've got the scanner connected to a powered hub which is then connected via an OTG Cable to the tablet.
Currently this does NOT allow charging of the tablet, but there are (allegedly) connectors out there that work with some tablets. I've also spotted some cables that have a switch so that you can either charge the tablet or use the scanner. This is not very elegant though. I'm still researching this. If you have any known solutions to this then please post your results.

  • Loss of virtual keyboard functionality
When the scanner is connected, the virtual keyboard is disabled, so you cannot enter data into any field that requires normal text. However I've discovered that this does not apply to Bluetooth keyboards, so I've now connected an Apple Bluetooth Keyboard and this combination of scanner and keyboard do work together.

As a supplementary on this, when the BlueTooth keyboard is out of range, the device does NOT revert automatically to the virtual keyboard, you have to reselect it in the settings.

  • Coding Issues
I've set my scanner up so that it is continuously scanning for barcodes, and to add a CRLF at the end of each successful scan. I then set up a text box with the focus to receive the barcodes, and then used the "EnterPressed" event to get the scan data.

I had a serious problem with my code though in that it worked for a single scan then the Activity terminated with no error message. I suspect that this is something to do the messaging processes in B4A and I've found that the solution was to use a CallSubDelayed to let the system handle internal messages first.

Sub txtNextItem_EnterPressed
End Sub

Sub DelayedNextItem
    Dim itemcode As String

    Log("txtNextItem_EnterPressed with '" & itemcode & "'")

' ======== pROCESS THE iNFO HERE ======

    log("Finished adding Item")

' Set field up for next scan
        txtNextItem.Hint="Add another"
    End Try   
End Sub

That's where I am currently. Any comments/ideas welcomed.