Android: Listening for barcode scanner button bein

2019-09-05 00:31发布

问题:

I have a Motorola TC55, that is equipped with a hardware barcode scanner. What i'd like to do is listen for that button being pressed in my app. I've googled and looked on SO without any luck. Can someone point me to a resource, or suggest how i can get started?

回答1:

On the Motorola TC55 the hardware scan button is mapped to the key "BUTTON_L1" by default so this is what you'd listen for like below.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  if(keyCode == KeyEvent.KEYCODE_BUTTON_L1 {
    //Do something scanner was pressed.
  }
}

You can see the key it is mapped to through Settings->Programmable Keys