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!
Audiomanager maudiomanager = (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
Max = maudiomanager. getstreammaxvolume (audiomanager. stream_alarm );
Current = maudiomanager. getstreamvolume (audiomanager. stream_alarm );
Log. D ("alarm", "MAX:" + MAX + "current:" + current );
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, for example, audiomanager. stream_voice_call, audiomanager. stream_system, etc. Index is the volume size falgs as 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 and set the mute system. Out. println ("ismicrophonemute =" + audiomanager. ismicrophonemute () during the call ());
Audiomanager. setmicrophonemute (! Audiomanager. ismicrophonemute (); // sets hands-free mode during calls.
System. Out. println ("isspeakerphoneon =" + audiomanager. isspeakerphoneon ());
Audiomanager. setspeakerphoneon (! Audiomanager. isspeakerphoneon (); // do not forget the modified permission <uses-Permission Android: Name = "android. Permission. modify_audio_settings"/>