本文介绍了接管在Android上的音量键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想借此overinput在音量上下。此刻我的code是:
@覆盖
公共布尔的onkeydown(INT键code,KeyEvent的事件){
Log.v(TAG,event.toString());
如果(键code == KeyEvent.KEY code_VOLUME_DOWN){
mLamp.moveBackward();
返回false;
}
否则,如果(键code == KeyEvent.KEY code_VOLUME_UP){
mLamp.moveForward();
返回false;
}
返回true;
}
公共布尔的onkeyup(INT键code,KeyEvent的事件){
Log.v(TAG,event.toString());
如果(键code == KeyEvent.KEY code_VOLUME_DOWN){
返回false;
}
否则,如果(键code == KeyEvent.KEY code_VOLUME_UP){
返回false;
}
返回true;
}
这会触发 mLamp.moveBackward()
和 mLamp.moveForward()
的功能,但它仍然改变音量的铃声。我有什么做的铃声音量不改?
解决方案
I want to take overinput over the Volume Up and Down. At the moment my code is:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.v(TAG, event.toString());
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
mLamp.moveBackward();
return false;
}
else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP){
mLamp.moveForward();
return false;
}
return true;
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
Log.v(TAG, event.toString());
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
return false;
}
else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP){
return false;
}
return true;
}
This triggers the mLamp.moveBackward()
and mLamp.moveForward()
function but it still changes the volume of the ringer.What do I have to do that the ringer loudness doesn't change?
解决方案
这篇关于接管在Android上的音量键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!