直接监听onKeyDown方法
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (KeyEvent.KEYCODE_HEADSETHOOK == keyCode) { //按下了耳机键
- if (event.getRepeatCount() == 0) { //如果长按的话,getRepeatCount值会一直变大
- //短按
- } else {
- //长按
- }
- }
- }
-
2023-11-23 15:26:16
直接监听onKeyDown方法