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

游戏过程中只允许调整多媒体音量,而不允许调整通话音量。

需要添加权限<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 

posted on 2013-05-27 16:12  瓦楞球  阅读(9213)  评论(0编辑  收藏  举报