The Audiomanager class is located on Android. Media package, this class provides access to control volume and sound mode operation
The following are the Audiomanager ways to set the sound mode and adjust the sound size.
How to get the Sound manager:
The code is as follows |
Copy Code |
Audiomanager Audiomanager = (audiomanager) getsystemservice (Audio_service); |
The Main method inside:
A, set the sound mode
The code is as follows |
Copy Code |
Sound mode Audiomanager.setringermode (Audiomanager.ringer_mode_normal); Mute mode Audiomanager.setringermode (audiomanager.ringer_mode_silent); Vibration mode Audiomanager.setringermode (audiomanager.ringer_mode_vibrate); |
B, adjust the sound size
The code is as follows |
Copy Code |
Reduce sound Volume Audiomanager.adjustvolume (audiomanager.adjust_lower, 0); Increase the volume of sound Audiomanager.adjustvolume (audiomanager.adjust_raise, 0); |
(when the first parameter passed in is Audiomanager.adjust_lower, you can turn the volume down one unit, and when you pass in the Audiomanager.adjust_raise, turn the volume up one unit.) )
GetMode () Get audio mode
Getringermode () Get ring Vibration mode
Audiomanager
public void Setstreammute (int streamtype, Boolean state)
Mute or not mute the audio stream.
Mute commands are protected from client process death: If the process dies with an active mute request on the stream, the stream is automatically muted.
For a given stream, the mute request is cumulative: Audiomanager receives several mute requests from one or more clients, and the mute is Shireu only if the same number of cancellation requests is received.
For a better user experience, the program must remove the muted stream from the OnPause (), if appropriate, mute again in Onresume ()
This method can be used only for platform-wide management applications or primary telephony applications that replace audio settings.
Parameters
Streamtype to Mute/cancel the quiet stream.
State Requests Mute Status: If true, mute, and if false, suppress mute.
If you use the mode associated with the phone vibration, remember to add permissions. Android.permission.VIBRATE Oh!