Barcode Scanner on myPOS Slim Devices
The myPOS Slim terminal includes a built-in barcode scanner that works without requiring integration with the myPOS Smart SDK. The scanner emulates a keyboard input on Android, meaning it behaves like physical keystrokes being typed into the device.
Integration Methods
There are two primary methods to capture barcode data from the scanner:
Using EditText Input Field
This is the simplest approach. Just place focus on an EditText component in your layout, and the barcode scanner will automatically populate the scanned data as if typed by the user.
Useful for apps that already include form-based UI fields.
## 2️⃣ Using `dispatchKeyEvent` to Capture Input Programmatically
You can also handle the barcode input manually by overriding `dispatchKeyEvent()` in your `Activity`:
```json
String barcode = null;
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getAction() == KeyEvent.ACTION_DOWN) {
if (e.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Log.i("LOG", "scanned code: " + barcode);
barcode = null;
return false;
}
else {
if (barcode == null)
barcode = "";
char pressedKey = (char) e.getUnicodeChar();
barcode += pressedKey;
}
}
else if (e.getAction() == KeyEvent.ACTION_MULTIPLE) {
if (e.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN) {
barcode = e.getCharacters();
Log.i("LOG", "scanned code: " + e.getCharacters());
barcode = null;
}
}
return super.dispatchKeyEvent(e);
}
Tip: Use the KEYCODE_ENTER event to detect the end of a scan sequence, as barcode scanners typically append an Enter key after scanning.
This approach does not require the Smart SDK and works out of the box on myPOS Slim devices configured with barcode scanning support.