Handle barcode scanner value via Android device Handle barcode scanner value via Android device android android

Handle barcode scanner value via Android device


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:

@Overrideprotected 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; }


you will get the result on Activity keydown event.

For Example:-

@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {    char pressedKey = (char) event.getUnicodeChar();    Barcode += "" + pressedKey;    Toast.makeText(getApplicationContext(), "barcode--->>>" + Barcode, 1)            .show();    return true;}

Hope this post will help you.


I also had same problem,but when i used onKeyDown or onKeyUp,it was not called every time i mean for every character for barcode.I Used DiapatchKeyEvent,and it worked nice.