android 手机铃声获取

转载自:http://www.hlovey.cn/2009/09/24/android-ringtone-ringvolumn.html

通过程序获取android系统手机的铃声和音量。同样,设置铃声和音量的方法也很简单!

  1. AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

//通话音量

  1. int max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_VOICE_CALL );
  2. int current = mAudioManager.getStreamVolume( AudioManager.STREAM_VOICE_CALL );
  3. Log.d("VIOCE_CALL", "max : " + max + " current : " + current);

//系统音量

  1. max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_SYSTEM );
  2. current = mAudioManager.getStreamVolume( AudioManager.STREAM_SYSTEM );
  3. Log.d("SYSTEM", "max : " + max + " current : " + current);

//铃声音量

  1. max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_RING );
  2. current = mAudioManager.getStreamVolume( AudioManager.STREAM_RING );
  3. Log.d("RING", "max : " + max + " current : " + current);

//音乐音量,媒体音量

  1. max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_MUSIC );
  2. current = mAudioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
  3. Log.d("MUSIC", "max : " + max + " current : " + current);

//提示声音音量

  1. max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_ALARM );
  2. current = mAudioManager.getStreamVolume( AudioManager.STREAM_ALARM );
  3. Log.d("ALARM", "max : " + max + " current : " + current);

设置音量的方法也很简单,AudioManager提供了方法:
public void setStreamVolume(int streamType, int index, int flags)
其中 streamType 有内置的常量,去文档里面就可以看到

<!-- Ene TempSave-->

你可能感兴趣的:(android)