r/androiddev•
optical_power

I have a bluetooth scanner that appears as a keyboard. Some advice sought on best way to interface to it.

I have been asked to fix someone else's app as the original developer (from overseas) is no longer available. I'm completely new to Android programming though I'm an experienced PC programmer.

Since I have no documentation on the barcode scanner and none is being provided by the manufacturer, I resorted to writing some test code and determined that the scanner is appearing as a BT keyboard to the device and each scan is sent as a string of characters terminated by an Enter key stroke.

My question is how should I best tackle the capturing of these simulated keystrokes so that my app can (a) capture them correctly and (b) not lose events from the real keyboard/buttons.

What I've tried

So I hacked together a test app that had a text view, a listview and a button, and was able to override the onKeyDown of my activity to capture these keystrokes, build a string representing the barcode and put it into the list. It all works fine from the key capture aspect (inc checking repeat count as this was causing issues on a samsung device).

However when I put the relevant parts of this code into my real app I'm able to capture the character keystrokes but I find that the Enter keycode is not captured by my onKeyDown and that the back button is is not working any more. Further debugging shows that the back button is coming through my onKeyDown event handler while the Enter key is not.

TLDR; How best to capture keystrokes from a device pretending to be a keyboard while not losing events from the real buttons and keys.

Posted Jan 4, 2016, 11:11 AM UTC

710
Loading comments…