直接监听onKeyDown方法
-
-
public boolean onKeyDown(int keyCode, KeyEvent event) {
-
if (KeyEvent.KEYCODE_HEADSETHOOK == keyCode) { //按下了耳机键
-
if (event.getRepeatCount() == 0) { //如果长按的话,getRepeatCount值会一直变大
-
//短按
-
} else {
-
//长按
-
}
-
}
-
}
-
2021-12-14 03:31:53
直接监听onKeyDown方法