@Override public boolean onKeyDown(int keyCode, KeyEvent event) { AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP:// 音量增大 mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume+1, 1); break; case KeyEvent.KEYCODE_VOLUME_DOWN:// 音量减小 mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume-1, 1); break; case KeyEvent.KEYCODE_BACK:// 返回键 //jniOnCallCppEvent(); return true; //return super.onKeyDown(keyCode, event); default: break; } return true; //return super.onKeyDown(keyCode, event); }
![复制代码](https://common.cnblogs.com/images/copycode.gif)
游戏过程中只允许调整多媒体音量,而不允许调整通话音量。
需要添加权限<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
标签:return,AudioManager,KeyEvent,音量,多媒体,Android,mAudioManager,keyCode From: https://www.cnblogs.com/kn-zheng/p/17005258.html