android调音量

//音量控制,初始化定义
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
//最大音量
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
//当前音量
int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);


//降低音量,调出系统音量控制
if(flag ==0){
  mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_LOWER,
                            AudioManager.FX_FOCUS_NAVIGATION_UP);
}
//增加音量,调出系统音量控制
else if(flag == 1){
  mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_RAISE,
                            AudioManager.FX_FOCUS_NAVIGATION_UP);


你可能感兴趣的:(android开发)