The myPOS Slim device has a barcode scanner that can be utilized without the integration of the Smart SDK. It is used by emulating a keyboard directly from the Android and it can be used in two ways:
- The first option is to capture the barcode using the EditText UI component.
- The second option is to use the standard function for key event handling. It can be seen from the example below:
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);
}