Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle barcode scanner value via Android device

I'm trying to handle value from a barcode scanner USB via my Android 3.2 tablet, the scanner is succefuly working in the OS but i want to get the value in the program without a edittext, usbmanager host and accessory did not list it with the connected devices via USB.

like image 596
Anas BEKRI Avatar asked Jul 05 '12 17:07

Anas BEKRI


People also ask

Can we read barcode through mobile?

How do I scan a barcode to a website? Usually, if you are using a mobile device, you have to download a barcode app in the app store. It is simple to use once you have the application. Just point your phone/ tablet camera at the barcode, and the app should tell you if it has been scanned.


1 Answers

most plug in barcode scanners (that I've seen) are made as HID profile devices so whatever they are plugged into should see them as a Keyboard basically. I think this is why they do not show up in the USB host APIs list of accessories. You should be able to get raw input from them the same way you would a keyboard inside your Activity by overriding Activity.onKeyDown(int keycode, KeyEvent ke)

Something like this in your activity:

@Override
protected boolean onKeyDown(int keyCode, KeyEvent event) {
     Log.i("TAG", ""+ keyCode);
     //I think you'll have to manually check for the digits and do what you want with them.
     //Perhaps store them in a String until an Enter event comes in (barcode scanners i've used can be configured to send an enter keystroke after the code)
     return true;
 }
like image 117
FoamyGuy Avatar answered Sep 23 '22 15:09

FoamyGuy