home和音量键监听的onKeyDown与onKeyUp使用
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_VOLUME_DOWN){
return true;
}
else if(keyCode==KeyEvent.KEYCODE_VOLUME_UP) {
return true;
}else {
return super.onKeyDown(keyCode, event)
};
}
【home和音量键监听的onKeyDown与onKeyUp使用】音量调节蔽掉了,唯独不能屏蔽掉调节音量的声音可以试试另一个
两个都可以起到监听作用
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_VOLUME_DOWN){
return true;
}else if(keyCode==KeyEvent.KEYCODE_VOLUME_UP){
return true;
}else {
return super.onKeyUp(keyCode, event);
}
}
音量键调节
AudioManager audioManager= (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (keyCode==KeyEvent.KEYCODE_VOLUME_UP){
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,AudioManager.FX_FOCUS_NAVIGATION_UP);
}if (keyCode==KeyEvent.KEYCODE_VOLUME_DOWN){
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,AudioManager.FX_FOCUS_NAVIGATION_UP);
}
推荐阅读
- 急于表达——往往欲速则不达
- 第三节|第三节 快乐和幸福(12)
- 20170612时间和注意力开销记录
- 2.6|2.6 Photoshop操作步骤的撤消和重做 [Ps教程]
- 对称加密和非对称加密的区别
- 眼光要放高远
- 樱花雨
- 前任
- 2020-04-07vue中Axios的封装和API接口的管理
- 烦恼和幸福