本文介绍了使用音量键,而屏幕锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这code不工作将屏幕锁定。我该怎么办,如果我想音量键的工作,而屏幕锁定?
我的code是:
@覆盖
公共布尔dispatchKeyEvent(KeyEvent的事件){
INT行动= event.getAction();
INT键code = event.getKey code();
开关(钥匙code){
案例KeyEvent.KEY code_VOLUME_UP:
如果(动作== KeyEvent.ACTION_UP){
//去做
}
返回true;
案例KeyEvent.KEY code_VOLUME_DOWN:
如果(动作== KeyEvent.ACTION_DOWN){
//去做
}
返回true;
默认:
返回super.dispatchKeyEvent(事件);
}
}
解决方案
您可以注册的BroadcastReceiver
与行动android.media.VOLUME_CHANGED_ACTION:
android.media.VOLUME_CHANGED_ACTION
做的另一种方法是:在Android 音量键。
This code doesn't work will screen locked. what should I do if I want volume key work while screen locked?
My code is :
@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);
}
}
解决方案
you can register BroadcastReceiver
with action "android.media.VOLUME_CHANGED_ACTION" :
android.media.VOLUME_CHANGED_ACTION
Other way of doing is: volume key on Android .
这篇关于使用音量键,而屏幕锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!