Search code examples
androidbarcode

Detect barcode scanning event from android-based mobile barcode scanner


There is a device with embedded laser barcode scanner and hardware SCAN button on Android 4.4.2. Is there any method to hook qr scan event with java interface? Device is Sunlux xl-8681d but it detects as x301 in adb device list.


Solution

  • I have worked with similar device. When you click on some area where you can edit text, and scan a bar code, will it print it on the field? If yes, then you can use the following snippet inside your Activity:

    Override dispatchKeyEvent method. Small sample:

       @Override
        public boolean dispatchKeyEvent(KeyEvent event) {
            if (event.getCharacters() != null && !event.getCharacters().isEmpty())
            //Add more code...
            return super.dispatchKeyEvent(event);
    
        }