Android: Listening for barcode scanner button being pressed

家住魔仙堡 提交于 2019-12-12 04:48:37

问题


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



来源:https://stackoverflow.com/questions/29677725/android-listening-for-barcode-scanner-button-being-pressed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!