How to Support Barcode Scanner in Mobile Applications
Some mobile applications such as WebPOS or Mobile Warehouse Operations, benefit from the use of a barcode scanner as an input device.
This article explains what application changes are required to support it.
How Barcode Scanners Work
When a barcode scanner is connected (via USB or BlueTooth) to a mobile device it works as a hardware keyboard.
Depending on the device and its operating system, it might be required to put the focus in a text input field in order to be able to work with the scanner. Openbravo Mobile applications deal with them by setting the focus in an input text named focusKeeper that is positioned out of the screen. As said, the focusKeeper object is a HTML
'input' of type
Configuring the Application to Work
In order to enable the focusKeeper, the application must configure it, otherwise the focus will not be set on it.
This is done by setting the global
useBarcode terminal property to
true. Each application can decide how this property should be set (as a backend configuration, fix for the whole application, asking the user to set it up in the UI, etc...)
As for the same application, there could be some windows (or even parts of a window) where the barcode scanner should be enabled and other ones where it should not. It is required to programmatically specify whether focusKeeper should be used. This is done by
focus boolean parameter determines whether it should be used or not. If is to be used in the whole window, a good place to set it, is in its
Behavior in Different Devices
The behavior of barcode scanners can vary depending on the scanner itself and, more often, in the mobile device hardware and operating system. This is the reason why it is highly advisable to test the application with the target devices.
- The scanner only works in case the focus is set in focusKeeper
- Both virtual and hardware keyboards, are not supported at the same time. In order to allow typing with the on-screen keyboard, the barcode scanner must be disabled first. Some barcode scanners allow to be temporarily disabled by pressing a button on them
- When the focus is in focusKeeper and the barcode scanner is not enabled (or not connected), the on-screen keyboard is allways shown
- It is necessary to click in "SCAN" button always that the user want to use the barcode scanner
Android < 4.2
Note that Chrome and the Stock browser behave differently.
- Both virtual and hardware keyboards, are supported at the same time
- In most devices, when the focus is set in the focusKeeper, the on-screen keyboard is not seen
- Chrome: In most devices, focusKeeper is not required (though is not harmful) because it is possible to scan even not having the focus in a text field
- Stock browser: If focusKeeper is not used, and after scanning the first character, the focus goes to the URL bar, adding the rest of characters there. So focusKeeper is required to work propertly
Android >= 4.2
- Both virtual and hardware keyboards, are not supported at the same time. Disabling the barcode scanner first, is required to allow typing with the on-screen keyboard. The disable button on the scanner, doesn't work in these Android devices, so it is necessary to switch it off and on from the operating system
- In most devices, the focusKeeper is not required (though is not harmful) because it is possible to scan even without having the focus in a text field