3
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
//TODO
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
//TODO
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
此代碼在屏幕打開時工作。但屏幕鎖定時不行。屏幕鎖定時有沒有辦法獲得音量按鍵事件?如何在屏幕鎖定時獲取音量按鍵事件?
解鎖屏幕時要觸發它 – itsrajesh4uguys 2013-04-22 10:03:04
但我需要它,而鎖定 – user2306862 2013-04-22 10:09:07
我的意思解鎖programmatcally .. – itsrajesh4uguys 2013-04-22 10:12:22