gpt4 book ai didi

android - 接管 Android 上的音量键

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:08 28 4
gpt4 key购买 nike

我想接管音量调高和音量调低的过度输入。目前我的代码是:

@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;
}

这会触发 mLamp.moveBackward()mLamp.moveForward() 函数,但它仍然会改变铃声的音量。我必须怎么做才能使铃声响度不变?

最佳答案

If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

关于android - 接管 Android 上的音量键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3220556/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com