Android 程序获取、设置铃声和音量通过程序获取android系统手机的铃声和音量。同样,设置铃声和音量的方法也很简单,如下代码:
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
//通话音量 int max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_VOICE_CALL ); int current = mAudioManager.getStreamVolume( AudioManager.STREAM_VOICE_CALL ); Log.d(”VIOCE_CALL”, “max : ” + max + ” current : ” + current);
//系统音量 max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_SYSTEM ); current = mAudioManager.getStreamVolume( AudioManager.STREAM_SYSTEM ); Log.d(”SYSTEM”, “max : ” + max + ” current : ” + current);
//铃声音量 AudioManager.STREAM_RING
//音乐音量 AudioManager.STREAM_MUSIC
设置音量的方法也很简单,AudioManager提供了方法:
public void setStreamVolume(int streamType, int index, int flags)
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM); mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM,maxVolume,0);