How do I Receive USB Device Input
I am developing an application in Android 3.0
I have plugged a barcode scanner into my Acer a501 Tablet and it works sweet. If I select an EditText box, scan an item, the barcod开发者_JAVA百科e ID shows up inside that box, just a like a keyboard input.
However, I have a slightly more complicated use. I do not want to print the barcode ID into a EditText box but capture the data and store it into a variable anytime the barcode scanner scans something.
How do I directly connect to the USB device? Is there a listening function so as soon as the barcode scanner scans something I can capture the results?
I really appreciate the support!
It appears that the device sets itself up as a keyboard HID device, and then just interacts like an external hardware keyboard when it runs a scan. The android.hardware.usb tree would have been your best bet, but I'm guessing the HID driver will automatically take control and you really won't be able to get it to let go so you can directly communicate with it.
Your best bet might be to use dispatchKeyEvent
on an Activity and listen for a series of KeyEvent
s that are generated when the barcode scanner is used: you'd have to string them together and verify that they fit the format of a barcode but it would let you do a background capture without having to fiddle with the device drivers. Let me know if that works.
精彩评论