cocos2d-x 控制android硬件音量大小调节按钮

在GameActivity里面修改:

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

你可能感兴趣的:(cocos2d-x 控制android硬件音量大小调节按钮)