dispatchKeyEvent獲取掃描結果

這是在CSDN上看到的評論,列印出來的并沒有有關掃描的資訊,我把列印的日志放在了最外層,發現其中一條是有關掃描的條碼 event
Action:ACTION_MULTIPLE,keyCode:KEYCODE_UNKNOWN
dispatchKeyEvent: KeyEvent { action=ACTION_MULTIPLE, keyCode=KEYCODE_UNKNOWN, scanCode=0, characters="3433422404403", metaState=0, flags=0x0, repeatCount=0, eventTime=365996, downTime=365996, deviceId=-1, source=0x101 }
獲取掃描文本
上面獲取掃描文字使用 event.getUnicodeChar() 獲取,目前我列印出來的結果是 :0,上面列印的結果,我猜想是 event.getCharacters()
onKeyMultiple
action的型別是 ACTION_MULTIPLE,可直接通過重寫onKeyMultiple方法去過濾掉其他的event
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
Log.e("TAG", "onKeyMultiple------: " + event.toString());
Log.i("TAG", "onKeyMultiple------: " + event.getCharacters());
return super.onKeyMultiple(keyCode, repeatCount, event);
}
列印結果
E/TAG: onKeyMultiple------: KeyEvent { action=ACTION_MULTIPLE, keyCode=KEYCODE_UNKNOWN, scanCode=0, characters="3433422404403", metaState=0, flags=0x0, repeatCount=0, eventTime=3548959, downTime=3548959, deviceId=-1, source=0x101 }
I/TAG: onKeyMultiple------: 3433422404403
event.getCharacters()棄用問題 (回傳String)
https://stackoverflow.com/questions/59103860/android-keyevent-getcharacters-or-keyevent-characters-is-deprecated
并未找到可替代的方案,目前使用這種方式解決了現有問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/299906.html
標籤:其他
