The Android program obtains and sets the ringtone and volume.
Obtain the ringtones and volume of the android mobile phone through a program. Similarly, you can set the ringtone and volume easily!
AudioManagermAudioManager = (AudioManager) getSystemService (Context. AUDIO_SERVICE );
// Call volume
Int max = mAudioManager. getStreamMaxVolume (AudioManager. STREAM_VOICE_CALL );
Int current = mAudioManager. getStreamVolume (AudioManager. STREAM_VOICE_CALL );
Log. d ("VIOCE_CALL", "max:" + max + "current:" + current );
// System volume
Max = mAudioManager. getStreamMaxVolume (AudioManager. STREAM_SYSTEM );
Current = mAudioManager. getStreamVolume (AudioManager. STREAM_SYSTEM );
Log. d ("SYSTEM", "max:" + max + "current:" + current );
// Ringtone volume
Max = mAudioManager. getStreamMaxVolume (AudioManager. STREAM_RING );
Current = mAudioManager. getStreamVolume (AudioManager. STREAM_RING );
Log. d ("RING", "max:" + max + "current:" + current );
// Music volume
Max = mAudioManager. getStreamMaxVolume (AudioManager. STREAM_MUSIC );
Current = mAudioManager. getStreamVolume (AudioManager. STREAM_MUSIC );
Log. d ("MUSIC", "max:" + max + "current:" + current );
// Sound volume prompt
The method for setting the volume is also very simple. AudioManager provides the method:
Public void setStreamVolume (int streamType, int index, int flags)
StreamType is the ringtone type, such as AudioManager. STREAM_VOICE_CALL and AudioManager. STREAM_SYSTEM. The index is the volume size.
Falgs is the flag.
Set Vibration:
MVibrator = (Vibrator) mContext. getSystemService (Service. VIBRATOR_SERVICE );
Long [] pattern = {150,100}; // OFF/ON/OFF/ON...
MVibrator. vibrate (pattern,-1 );
Mute:
Set the system sound to 0.
// Set mute during a call
System. out. println ("isMicrophoneMute =" + audioManager. isMicrophoneMute ());
AudioManager. setMicrophoneMute (! AudioManager. isMicrophoneMute ());
// Set hands-free during calls
System. out. println ("isSpeakerphoneOn =" + audioManager. isSpeakerphoneOn ());
AudioManager. setSpeakerphoneOn (! AudioManager. isSpeakerphoneOn ());
// Do not forget the modified permissions.
Max = mAudioManager. getStreamMaxVolume (AudioManager. STREAM_ALARM );
Current = mAudioManager. getStreamVolume (AudioManager. STREAM_ALARM );
Log. d ("ALARM", "max:" + max + "current:" + current );