Android外付けスキャナー銃は通常入力イベントを傍受する
String barcode ="";
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(event.getAction()==KeyEvent.ACTION_DOWN){
Log.e("123123","dispatchKeyEvent: "+event.toString());
char pressedKey = (char) event.getUnicodeChar();
barcode += pressedKey;
}
if (event.getAction()==KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Toast.makeText(getApplicationContext(),
"barcode--->>>" + barcode, Toast.LENGTH_LONG)
.show();
Log.i("123123",barcode);
// Toast.makeText(MainActivity.this,barcode,Toast.LENGTH_LONG).show();
barcode="";
}
return super.dispatchKeyEvent(event);
}//
dispatchKeyEventメソッドを書き換えればよい