java.lang.Object | |
↳ | android.media.AudioManager |
AudioManager provides access to volume and ringer mode control.
Use Context.getSystemService(Context.AUDIO_SERVICE)
to get
an instance of this class.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | ACTION_AUDIO_BECOMING_NOISY | Broadcast intent, a hint for applications that audio is about to become 'noisy' due to a change in audio outputs. | |||||||||
int | ADJUST_LOWER | Decrease the ringer volume. | |||||||||
int | ADJUST_RAISE | Increase the ringer volume. | |||||||||
int | ADJUST_SAME | Maintain the previous ringer volume. | |||||||||
String | EXTRA_RINGER_MODE | The new ringer mode. | |||||||||
String | EXTRA_VIBRATE_SETTING | The new vibrate setting for a particular type. | |||||||||
String | EXTRA_VIBRATE_TYPE | The vibrate type whose setting has changed. | |||||||||
int | FLAG_ALLOW_RINGER_MODES | Whether to include ringer modes as possible options when changing volume. | |||||||||
int | FLAG_PLAY_SOUND | Whether to play a sound when changing the volume. | |||||||||
int | FLAG_REMOVE_SOUND_AND_VIBRATE | Removes any sounds/vibrate that may be in the queue, or are playing (related to changing volume). | |||||||||
int | FLAG_SHOW_UI | Show a toast containing the current volume. | |||||||||
int | FLAG_VIBRATE | Whether to vibrate if going into the vibrate ringer mode. | |||||||||
int | FX_FOCUS_NAVIGATION_DOWN | Focus has moved down | |||||||||
int | FX_FOCUS_NAVIGATION_LEFT | Focus has moved left | |||||||||
int | FX_FOCUS_NAVIGATION_RIGHT | Focus has moved right | |||||||||
int | FX_FOCUS_NAVIGATION_UP | Focus has moved up | |||||||||
int | FX_KEYPRESS_DELETE | IME delete keypress sound | |||||||||
int | FX_KEYPRESS_RETURN | IME return_keypress sound | |||||||||
int | FX_KEYPRESS_SPACEBAR | IME spacebar keypress sound | |||||||||
int | FX_KEYPRESS_STANDARD | IME standard keypress sound | |||||||||
int | FX_KEY_CLICK | Keyboard and direction pad click sound | |||||||||
int | MODE_CURRENT | Current audio mode. | |||||||||
int | MODE_INVALID | Invalid audio mode. | |||||||||
int | MODE_IN_CALL | In call audio mode. | |||||||||
int | MODE_NORMAL | Normal audio mode: not ringing and no call established. | |||||||||
int | MODE_RINGTONE | Ringing audio mode. | |||||||||
int | NUM_STREAMS | This constant is deprecated. Use AudioSystem.getNumStreamTypes() instead | |||||||||
String | RINGER_MODE_CHANGED_ACTION | Sticky broadcast intent action indicating that the ringer mode has changed. | |||||||||
int | RINGER_MODE_NORMAL | Ringer mode that may be audible and may vibrate. | |||||||||
int | RINGER_MODE_SILENT | Ringer mode that will be silent and will not vibrate. | |||||||||
int | RINGER_MODE_VIBRATE | Ringer mode that will be silent and will vibrate. | |||||||||
int | ROUTE_ALL | Used for mask parameter of setRouting(int, int, int). | |||||||||
int | ROUTE_BLUETOOTH | This constant is deprecated. use ROUTE_BLUETOOTH_SCO | |||||||||
int | ROUTE_BLUETOOTH_A2DP | Routing audio output to bluetooth A2DP | |||||||||
int | ROUTE_BLUETOOTH_SCO | Routing audio output to bluetooth SCO | |||||||||
int | ROUTE_EARPIECE | Routing audio output to earpiece | |||||||||
int | ROUTE_HEADSET | Routing audio output to headset | |||||||||
int | ROUTE_SPEAKER | Routing audio output to spaker | |||||||||
int | STREAM_ALARM | The audio stream for alarms | |||||||||
int | STREAM_MUSIC | The audio stream for music playback | |||||||||
int | STREAM_NOTIFICATION | The audio stream for notifications | |||||||||
int | STREAM_RING | The audio stream for the phone ring | |||||||||
int | STREAM_SYSTEM | The audio stream for system sounds | |||||||||
int | STREAM_VOICE_CALL | The audio stream for phone calls | |||||||||
int | USE_DEFAULT_STREAM_TYPE | Suggests using the default stream type. | |||||||||
String | VIBRATE_SETTING_CHANGED_ACTION | Broadcast intent action indicating that the vibrate setting has changed. | |||||||||
int | VIBRATE_SETTING_OFF | Vibrate setting that suggests to never vibrate. | |||||||||
int | VIBRATE_SETTING_ON | Vibrate setting that suggests to vibrate when possible. | |||||||||
int | VIBRATE_SETTING_ONLY_SILENT | Vibrate setting that suggests to only vibrate when in the vibrate ringer mode. | |||||||||
int | VIBRATE_TYPE_NOTIFICATION | Vibrate type that corresponds to notifications. | |||||||||
int | VIBRATE_TYPE_RINGER | Vibrate type that corresponds to the ringer. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adjusts the volume of a particular stream by one step in a direction.
| |||||||||||
Adjusts the volume of the most relevant stream, or the given fallback
stream.
| |||||||||||
Adjusts the volume of the most relevant stream.
| |||||||||||
Returns the current audio mode.
| |||||||||||
Returns the current ringtone mode.
| |||||||||||
Returns the current audio routing bit vector for a specified mode.
| |||||||||||
Returns the maximum volume index for a particular stream.
| |||||||||||
Returns the current volume index for a particular stream.
| |||||||||||
Returns whether the user's vibrate setting for a vibrate type.
| |||||||||||
Checks whether A2DP audio routing to the Bluetooth headset is on or off.
| |||||||||||
Checks whether audio routing to the Bluetooth headset is on or off.
| |||||||||||
Checks whether the microphone mute is on or off.
| |||||||||||
Checks whether any music is active.
| |||||||||||
Checks whether the speakerphone is on or off.
| |||||||||||
Load Sound effects.
| |||||||||||
Plays a sound effect (Key clicks, lid open/close...)
| |||||||||||
Plays a sound effect (Key clicks, lid open/close...)
| |||||||||||
Sets A2DP audio routing to the Bluetooth headset on or off.
| |||||||||||
Sets audio routing to the Bluetooth headset on or off.
| |||||||||||
Sets the microphone mute on or off.
| |||||||||||
Sets the audio mode.
| |||||||||||
Sets the ringer mode.
| |||||||||||
Sets the audio routing for a specified mode
| |||||||||||
Sets the speakerphone on or off.
| |||||||||||
Mute or unmute an audio stream.
| |||||||||||
Solo or unsolo a particular stream.
| |||||||||||
Sets the volume index for a particular stream.
| |||||||||||
Sets the setting for when the vibrate type should vibrate.
| |||||||||||
Returns whether a particular type should vibrate according to user
settings and the current ringer mode.
| |||||||||||
Unload Sound effects.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Broadcast intent, a hint for applications that audio is about to become 'noisy' due to a change in audio outputs. For example, this intent may be sent when a wired headset is unplugged, or when an A2DP audio sink is disconnected, and the audio system is about to automatically switch audio route to the speaker. Applications that are controlling audio streams may consider pausing, reducing volume or some other action on receipt of this intent so as not to surprise the user with audio from the speaker.
Decrease the ringer volume.
Increase the ringer volume.
Maintain the previous ringer volume. This may be useful when needing to show the volume toast without actually modifying the volume.
The new ringer mode.
The new vibrate setting for a particular type.
The vibrate type whose setting has changed.
Whether to include ringer modes as possible options when changing volume. For example, if true and volume level is 0 and the volume is adjusted with ADJUST_LOWER, then the ringer mode may switch the silent or vibrate mode.
By default this is on for the ring stream. If this flag is included, this behavior will be present regardless of the stream type being affected by the ringer mode.
Whether to play a sound when changing the volume.
If this is given to adjustVolume(int, int) or adjustSuggestedStreamVolume(int, int, int), it may be ignored in some cases (for example, the decided stream type is not STREAM_RING, or the volume is being adjusted downward).
Removes any sounds/vibrate that may be in the queue, or are playing (related to changing volume).
Show a toast containing the current volume.
Whether to vibrate if going into the vibrate ringer mode.
Current audio mode. Used to apply audio routing to current mode.
Invalid audio mode.
In call audio mode. A call is established.
Normal audio mode: not ringing and no call established.
Ringing audio mode. An incoming is being signaled.
This constant is deprecated.Use AudioSystem.getNumStreamTypes() instead
Sticky broadcast intent action indicating that the ringer mode has changed. Includes the new ringer mode.
Ringer mode that may be audible and may vibrate. It will be audible if the volume before changing out of this mode was audible. It will vibrate if the vibrate setting is on.
Ringer mode that will be silent and will not vibrate. (This overrides the vibrate setting.)
Ringer mode that will be silent and will vibrate. (This will cause the phone ringer to always vibrate, but the notification vibrate to only vibrate if set.)
Used for mask parameter of setRouting(int, int, int).
Routing audio output to bluetooth A2DP
Routing audio output to bluetooth SCO
Routing audio output to earpiece
Routing audio output to headset
Routing audio output to spaker
The audio stream for alarms
The audio stream for music playback
The audio stream for notifications
The audio stream for the phone ring
The audio stream for system sounds
The audio stream for phone calls
Suggests using the default stream type. This may not be used in all places a stream type is needed.
Broadcast intent action indicating that the vibrate setting has changed. Includes the vibrate type and its new setting.
Vibrate setting that suggests to never vibrate.
Vibrate setting that suggests to vibrate when possible.
Vibrate setting that suggests to only vibrate when in the vibrate ringer mode.
Vibrate type that corresponds to notifications.
Vibrate type that corresponds to the ringer.
Adjusts the volume of a particular stream by one step in a direction.
streamType | The stream type to adjust. One of STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC or STREAM_ALARM |
---|---|
direction | The direction to adjust the volume. One of ADJUST_LOWER, ADJUST_RAISE, or ADJUST_SAME. |
flags | One or more flags. |
Adjusts the volume of the most relevant stream, or the given fallback stream.
direction | The direction to adjust the volume. One of ADJUST_LOWER, ADJUST_RAISE, or ADJUST_SAME. |
---|---|
suggestedStreamType | The stream type that will be used if there isn't a relevant stream. USE_DEFAULT_STREAM_TYPE is valid here. |
flags | One or more flags. |
Adjusts the volume of the most relevant stream. For example, if a call is active, it will have the highest priority regardless of if the in-call screen is showing. Another example, if music is playing in the background and a call is not active, the music stream will be adjusted.
direction | The direction to adjust the volume. One of ADJUST_LOWER, ADJUST_RAISE, or ADJUST_SAME. |
---|---|
flags | One or more flags. |
Returns the current audio mode.
Returns the current ringtone mode.
Returns the current audio routing bit vector for a specified mode.
mode | audio mode to get route (e.g., MODE_RINGTONE) |
---|
Returns the maximum volume index for a particular stream.
streamType | The stream type whose maximum volume index is returned. |
---|
Returns the current volume index for a particular stream.
streamType | The stream type whose volume index is returned. |
---|
Returns whether the user's vibrate setting for a vibrate type.
This shouldn't be needed by most clients that want to vibrate, instead see shouldVibrate(int).
vibrateType | The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER. |
---|
Checks whether A2DP audio routing to the Bluetooth headset is on or off.
Checks whether audio routing to the Bluetooth headset is on or off.
Checks whether the microphone mute is on or off.
Checks whether any music is active.
Checks whether the speakerphone is on or off.
Load Sound effects. This method must be called when sound effects are enabled.
Plays a sound effect (Key clicks, lid open/close...)
effectType | The type of sound effect. One of FX_KEY_CLICK, FX_FOCUS_NAVIGATION_UP, FX_FOCUS_NAVIGATION_DOWN, FX_FOCUS_NAVIGATION_LEFT, FX_FOCUS_NAVIGATION_RIGHT, FX_KEYPRESS_STANDARD, FX_KEYPRESS_SPACEBAR, FX_KEYPRESS_DELETE, FX_KEYPRESS_RETURN, |
---|---|
volume | Sound effect volume NOTE: This version is for applications that have their own settings panel for enabling and controlling volume. |
Plays a sound effect (Key clicks, lid open/close...)
effectType | The type of sound effect. One of FX_KEY_CLICK, FX_FOCUS_NAVIGATION_UP, FX_FOCUS_NAVIGATION_DOWN, FX_FOCUS_NAVIGATION_LEFT, FX_FOCUS_NAVIGATION_RIGHT, FX_KEYPRESS_STANDARD, FX_KEYPRESS_SPACEBAR, FX_KEYPRESS_DELETE, FX_KEYPRESS_RETURN, NOTE: This version uses the UI settings to determine whether sounds are heard or not. |
---|
Sets A2DP audio routing to the Bluetooth headset on or off.
on | set true to route A2DP audio to/from Bluetooth headset; false disable A2DP audio |
---|
Sets audio routing to the Bluetooth headset on or off.
on | set true to route SCO (voice) audio to/from Bluetooth headset; false to route audio to/from phone earpiece |
---|
Sets the microphone mute on or off.
on | set true to mute the microphone; false to turn mute off |
---|
Sets the audio mode.
mode | the requested audio mode (NORMAL, RINGTONE, or IN_CALL). Informs the HAL about the current audio state so that it can route the audio appropriately. |
---|
Sets the ringer mode.
Silent mode will mute the volume and will not vibrate. Vibrate mode will mute the volume and vibrate. Normal mode will be audible and may vibrate according to user settings.
ringerMode | The ringer mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE. |
---|
Sets the audio routing for a specified mode
mode | audio mode to change route. E.g., MODE_RINGTONE. |
---|---|
routes | bit vector of routes requested, created from one or more of ROUTE_xxx types. Set bits indicate that route should be on |
mask | bit vector of routes to change, created from one or more of ROUTE_xxx types. Unset bits indicate the route should be left unchanged |
Sets the speakerphone on or off.
on | set true to turn on speakerphone; false to turn it off |
---|
Mute or unmute an audio stream.
The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically.
The mute requests for a given stream are cumulative: the AudioManager can receive several mute requests from one or more clients and the stream will be unmuted only when the same number of unmute requests are received.
For a better user experience, applications MUST unmute a muted stream in onPause() and mute is again in onResume() if appropriate.
streamType | The stream to be muted/unmuted. |
---|---|
state | The required mute state: true for mute ON, false for mute OFF |
Solo or unsolo a particular stream. All other streams are muted.
The solo command is protected against client process death: if a process with an active solo request on a stream dies, all streams that were muted because of this request will be unmuted automatically.
The solo requests for a given stream are cumulative: the AudioManager can receive several solo requests from one or more clients and the stream will be unsoloed only when the same number of unsolo requests are received.
For a better user experience, applications MUST unsolo a soloed stream in onPause() and solo is again in onResume() if appropriate.
streamType | The stream to be soloed/unsoloed. |
---|---|
state | The required solo state: true for solo ON, false for solo OFF |
Sets the volume index for a particular stream.
streamType | The stream whose volume index should be set. |
---|---|
index | The volume index to set. See getStreamMaxVolume(int) for the largest valid value. |
flags | One or more flags. |
Sets the setting for when the vibrate type should vibrate.
vibrateType | The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER. |
---|---|
vibrateSetting | The vibrate setting, one of VIBRATE_SETTING_ON, VIBRATE_SETTING_OFF, or VIBRATE_SETTING_ONLY_SILENT. |
Returns whether a particular type should vibrate according to user settings and the current ringer mode.
This shouldn't be needed by most clients that use notifications to vibrate. The notification manager will not vibrate if the policy doesn't allow it, so the client should always set a vibrate pattern and let the notification manager control whether or not to actually vibrate.
vibrateType | The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER. |
---|
Unload Sound effects. This method can be called to free some memory when sound effects are disabled.