public class

AudioManager

extends Object
java.lang.Object
   ↳ android.media.AudioManager

Class Overview

AudioManager provides access to volume and ringer mode control.

Use Context.getSystemService(Context.AUDIO_SERVICE) to get an instance of this class.

Summary

Nested Classes
interface AudioManager.OnAudioFocusChangeListener Interface definition for a callback to be invoked when the audio focus of the system is updated. 
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.
String ACTION_SCO_AUDIO_STATE_CHANGED Sticky broadcast intent action indicating that the bluetoooth SCO audio connection state has changed.
int ADJUST_LOWER Decrease the ringer volume.
int ADJUST_RAISE Increase the ringer volume.
int ADJUST_SAME Maintain the previous ringer volume.
int AUDIOFOCUS_GAIN Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration.
int AUDIOFOCUS_GAIN_TRANSIENT Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time.
int AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, and where it is acceptable for other audio applications to keep playing after having lowered their output level (also referred to as "ducking").
int AUDIOFOCUS_LOSS Used to indicate a loss of audio focus of unknown duration.
int AUDIOFOCUS_LOSS_TRANSIENT Used to indicate a transient loss of audio focus.
int AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK Used to indicate a transient loss of audio focus where the loser of the audio focus can lower its output volume if it wants to continue playing (also referred to as "ducking"), as the new focus owner doesn't require others to be silent.
int AUDIOFOCUS_REQUEST_FAILED A failed focus change request.
int AUDIOFOCUS_REQUEST_GRANTED A successful focus change request.
String EXTRA_RINGER_MODE The new ringer mode.
String EXTRA_SCO_AUDIO_STATE Extra for intent ACTION_SCO_AUDIO_STATE_CHANGED containing the new bluetooth SCO connection state.
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 This constant is deprecated. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_BLUETOOTH This constant is deprecated. use ROUTE_BLUETOOTH_SCODo not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_BLUETOOTH_A2DP This constant is deprecated. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_BLUETOOTH_SCO This constant is deprecated. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_EARPIECE This constant is deprecated. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_HEADSET This constant is deprecated. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_SPEAKER This constant is deprecated. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int SCO_AUDIO_STATE_CONNECTED Value for extra EXTRA_SCO_AUDIO_STATE indicating that the SCO audio channel is established
int SCO_AUDIO_STATE_DISCONNECTED Value for extra EXTRA_SCO_AUDIO_STATE indicating that the SCO audio channel is not established
int SCO_AUDIO_STATE_ERROR Value for extra EXTRA_SCO_AUDIO_STATE indicating that there was an error trying to obtain the state
int STREAM_ALARM The audio stream for alarms
int STREAM_DTMF The audio stream for DTMF Tones
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
int abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l)
Abandon audio focus.
void adjustStreamVolume(int streamType, int direction, int flags)
Adjusts the volume of a particular stream by one step in a direction.
void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags)
Adjusts the volume of the most relevant stream, or the given fallback stream.
void adjustVolume(int direction, int flags)
Adjusts the volume of the most relevant stream.
int getMode()
Returns the current audio mode.
String getParameters(String keys)
Sets a varaible number of parameter values to audio hardware.
int getRingerMode()
Returns the current ringtone mode.
int getRouting(int mode)
This method is deprecated. Do not query audio routing directly, use isSpeakerphoneOn(), isBluetoothScoOn(), isBluetoothA2dpOn() and isWiredHeadsetOn() methods instead.
int getStreamMaxVolume(int streamType)
Returns the maximum volume index for a particular stream.
int getStreamVolume(int streamType)
Returns the current volume index for a particular stream.
int getVibrateSetting(int vibrateType)
Returns whether the user's vibrate setting for a vibrate type.
boolean isBluetoothA2dpOn()
Checks whether A2DP audio routing to the Bluetooth headset is on or off.
boolean isBluetoothScoAvailableOffCall()
Indicates if current platform supports use of SCO for off call use cases.
boolean isBluetoothScoOn()
Checks whether communications use Bluetooth SCO.
boolean isMicrophoneMute()
Checks whether the microphone mute is on or off.
boolean isMusicActive()
Checks whether any music is active.
boolean isSpeakerphoneOn()
Checks whether the speakerphone is on or off.
boolean isWiredHeadsetOn()
Checks whether audio routing to the wired headset is on or off.
void loadSoundEffects()
Load Sound effects.
void playSoundEffect(int effectType, float volume)
Plays a sound effect (Key clicks, lid open/close...)
void playSoundEffect(int effectType)
Plays a sound effect (Key clicks, lid open/close...)
void registerMediaButtonEventReceiver(ComponentName eventReceiver)
Register a component to be the sole receiver of MEDIA_BUTTON intents.
int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint)
Request audio focus.
void setBluetoothA2dpOn(boolean on)
This method is deprecated. Do not use.
void setBluetoothScoOn(boolean on)
Request use of Bluetooth SCO headset for communications.
void setMicrophoneMute(boolean on)
Sets the microphone mute on or off.
void setMode(int mode)
Sets the audio mode.
void setParameters(String keyValuePairs)
Sets a variable number of parameter values to audio hardware.
void setRingerMode(int ringerMode)
Sets the ringer mode.
void setRouting(int mode, int routes, int mask)
This method is deprecated. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
void setSpeakerphoneOn(boolean on)
Sets the speakerphone on or off.
void setStreamMute(int streamType, boolean state)
Mute or unmute an audio stream.
void setStreamSolo(int streamType, boolean state)
Solo or unsolo a particular stream.
void setStreamVolume(int streamType, int index, int flags)
Sets the volume index for a particular stream.
void setVibrateSetting(int vibrateType, int vibrateSetting)
Sets the setting for when the vibrate type should vibrate.
void setWiredHeadsetOn(boolean on)
This method is deprecated. Do not use.
boolean shouldVibrate(int vibrateType)
Returns whether a particular type should vibrate according to user settings and the current ringer mode.
void startBluetoothSco()
Start bluetooth SCO audio connection.
void stopBluetoothSco()
Stop bluetooth SCO audio connection.
void unloadSoundEffects()
Unload Sound effects.
void unregisterMediaButtonEventReceiver(ComponentName eventReceiver)
Unregister the receiver of MEDIA_BUTTON intents.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_AUDIO_BECOMING_NOISY

Since: API Level 3

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.

Constant Value: "android.media.AUDIO_BECOMING_NOISY"

public static final String ACTION_SCO_AUDIO_STATE_CHANGED

Since: API Level 8

Sticky broadcast intent action indicating that the bluetoooth SCO audio connection state has changed. The intent contains on extra EXTRA_SCO_AUDIO_STATE indicating the new state which is either SCO_AUDIO_STATE_DISCONNECTED or SCO_AUDIO_STATE_CONNECTED

Constant Value: "android.media.SCO_AUDIO_STATE_CHANGED"

public static final int ADJUST_LOWER

Since: API Level 1

Decrease the ringer volume.

Constant Value: -1 (0xffffffff)

public static final int ADJUST_RAISE

Since: API Level 1

Increase the ringer volume.

Constant Value: 1 (0x00000001)

public static final int ADJUST_SAME

Since: API Level 1

Maintain the previous ringer volume. This may be useful when needing to show the volume toast without actually modifying the volume.

Constant Value: 0 (0x00000000)

public static final int AUDIOFOCUS_GAIN

Since: API Level 8

Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration.

Constant Value: 1 (0x00000001)

public static final int AUDIOFOCUS_GAIN_TRANSIENT

Since: API Level 8

Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time. Examples of temporary changes are the playback of driving directions, or an event notification.

Constant Value: 2 (0x00000002)

public static final int AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK

Since: API Level 8

Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, and where it is acceptable for other audio applications to keep playing after having lowered their output level (also referred to as "ducking"). Examples of temporary changes are the playback of driving directions where playback of music in the background is acceptable.

Constant Value: 3 (0x00000003)

public static final int AUDIOFOCUS_LOSS

Since: API Level 8

Used to indicate a loss of audio focus of unknown duration.

Constant Value: -1 (0xffffffff)

public static final int AUDIOFOCUS_LOSS_TRANSIENT

Since: API Level 8

Used to indicate a transient loss of audio focus.

Constant Value: -2 (0xfffffffe)

public static final int AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK

Since: API Level 8

Used to indicate a transient loss of audio focus where the loser of the audio focus can lower its output volume if it wants to continue playing (also referred to as "ducking"), as the new focus owner doesn't require others to be silent.

Constant Value: -3 (0xfffffffd)

public static final int AUDIOFOCUS_REQUEST_FAILED

Since: API Level 8

A failed focus change request.

Constant Value: 0 (0x00000000)

public static final int AUDIOFOCUS_REQUEST_GRANTED

Since: API Level 8

A successful focus change request.

Constant Value: 1 (0x00000001)

public static final String EXTRA_RINGER_MODE

Since: API Level 1

The new ringer mode.

Constant Value: "android.media.EXTRA_RINGER_MODE"

public static final String EXTRA_SCO_AUDIO_STATE

Since: API Level 8

Extra for intent ACTION_SCO_AUDIO_STATE_CHANGED containing the new bluetooth SCO connection state.

Constant Value: "android.media.extra.SCO_AUDIO_STATE"

public static final String EXTRA_VIBRATE_SETTING

Since: API Level 1

The new vibrate setting for a particular type.

Constant Value: "android.media.EXTRA_VIBRATE_SETTING"

public static final String EXTRA_VIBRATE_TYPE

Since: API Level 1

The vibrate type whose setting has changed.

Constant Value: "android.media.EXTRA_VIBRATE_TYPE"

public static final int FLAG_ALLOW_RINGER_MODES

Since: API Level 1

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.

Constant Value: 2 (0x00000002)

public static final int FLAG_PLAY_SOUND

Since: API Level 1

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).

Constant Value: 4 (0x00000004)

public static final int FLAG_REMOVE_SOUND_AND_VIBRATE

Since: API Level 1

Removes any sounds/vibrate that may be in the queue, or are playing (related to changing volume).

Constant Value: 8 (0x00000008)

public static final int FLAG_SHOW_UI

Since: API Level 1

Show a toast containing the current volume.

Constant Value: 1 (0x00000001)

public static final int FLAG_VIBRATE

Since: API Level 1

Whether to vibrate if going into the vibrate ringer mode.

Constant Value: 16 (0x00000010)

public static final int FX_FOCUS_NAVIGATION_DOWN

Since: API Level 1

Focus has moved down

Constant Value: 2 (0x00000002)

public static final int FX_FOCUS_NAVIGATION_LEFT

Since: API Level 1

Focus has moved left

Constant Value: 3 (0x00000003)

public static final int FX_FOCUS_NAVIGATION_RIGHT

Since: API Level 1

Focus has moved right

Constant Value: 4 (0x00000004)

public static final int FX_FOCUS_NAVIGATION_UP

Since: API Level 1

Focus has moved up

Constant Value: 1 (0x00000001)

public static final int FX_KEYPRESS_DELETE

Since: API Level 3

IME delete keypress sound

Constant Value: 7 (0x00000007)

public static final int FX_KEYPRESS_RETURN

Since: API Level 3

IME return_keypress sound

Constant Value: 8 (0x00000008)

public static final int FX_KEYPRESS_SPACEBAR

Since: API Level 3

IME spacebar keypress sound

Constant Value: 6 (0x00000006)

public static final int FX_KEYPRESS_STANDARD

Since: API Level 3

IME standard keypress sound

Constant Value: 5 (0x00000005)

public static final int FX_KEY_CLICK

Since: API Level 1

Keyboard and direction pad click sound

Constant Value: 0 (0x00000000)

public static final int MODE_CURRENT

Since: API Level 1

Current audio mode. Used to apply audio routing to current mode.

Constant Value: -1 (0xffffffff)

public static final int MODE_INVALID

Since: API Level 1

Invalid audio mode.

Constant Value: -2 (0xfffffffe)

public static final int MODE_IN_CALL

Since: API Level 1

In call audio mode. A telephony call is established.

Constant Value: 2 (0x00000002)

public static final int MODE_NORMAL

Since: API Level 1

Normal audio mode: not ringing and no call established.

Constant Value: 0 (0x00000000)

public static final int MODE_RINGTONE

Since: API Level 1

Ringing audio mode. An incoming is being signaled.

Constant Value: 1 (0x00000001)

public static final int NUM_STREAMS

Since: API Level 1

This constant is deprecated.
Use AudioSystem.getNumStreamTypes() instead

Constant Value: 5 (0x00000005)

public static final String RINGER_MODE_CHANGED_ACTION

Since: API Level 1

Sticky broadcast intent action indicating that the ringer mode has changed. Includes the new ringer mode.

Constant Value: "android.media.RINGER_MODE_CHANGED"

public static final int RINGER_MODE_NORMAL

Since: API Level 1

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.

Constant Value: 2 (0x00000002)

public static final int RINGER_MODE_SILENT

Since: API Level 1

Ringer mode that will be silent and will not vibrate. (This overrides the vibrate setting.)

Constant Value: 0 (0x00000000)

public static final int RINGER_MODE_VIBRATE

Since: API Level 1

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.)

Constant Value: 1 (0x00000001)

public static final int ROUTE_ALL

Since: API Level 1

This constant is deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.

Used for mask parameter of setRouting(int, int, int).

Constant Value: -1 (0xffffffff)

public static final int ROUTE_BLUETOOTH

Since: API Level 1

This constant is deprecated.
use ROUTE_BLUETOOTH_SCODo not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.

Constant Value: 4 (0x00000004)

public static final int ROUTE_BLUETOOTH_A2DP

Since: API Level 3

This constant is deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.

Routing audio output to bluetooth A2DP

Constant Value: 16 (0x00000010)

public static final int ROUTE_BLUETOOTH_SCO

Since: API Level 3

This constant is deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.

Routing audio output to bluetooth SCO

Constant Value: 4 (0x00000004)

public static final int ROUTE_EARPIECE

Since: API Level 1

This constant is deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.

Routing audio output to earpiece

Constant Value: 1 (0x00000001)

public static final int ROUTE_HEADSET

Since: API Level 1

This constant is deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.

Routing audio output to headset

Constant Value: 8 (0x00000008)

public static final int ROUTE_SPEAKER

Since: API Level 1

This constant is deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.

Routing audio output to speaker

Constant Value: 2 (0x00000002)

public static final int SCO_AUDIO_STATE_CONNECTED

Since: API Level 8

Value for extra EXTRA_SCO_AUDIO_STATE indicating that the SCO audio channel is established

Constant Value: 1 (0x00000001)

public static final int SCO_AUDIO_STATE_DISCONNECTED

Since: API Level 8

Value for extra EXTRA_SCO_AUDIO_STATE indicating that the SCO audio channel is not established

Constant Value: 0 (0x00000000)

public static final int SCO_AUDIO_STATE_ERROR

Since: API Level 8

Value for extra EXTRA_SCO_AUDIO_STATE indicating that there was an error trying to obtain the state

Constant Value: -1 (0xffffffff)

public static final int STREAM_ALARM

Since: API Level 1

The audio stream for alarms

Constant Value: 4 (0x00000004)

public static final int STREAM_DTMF

Since: API Level 5

The audio stream for DTMF Tones

Constant Value: 8 (0x00000008)

public static final int STREAM_MUSIC

Since: API Level 1

The audio stream for music playback

Constant Value: 3 (0x00000003)

public static final int STREAM_NOTIFICATION

Since: API Level 3

The audio stream for notifications

Constant Value: 5 (0x00000005)

public static final int STREAM_RING

Since: API Level 1

The audio stream for the phone ring

Constant Value: 2 (0x00000002)

public static final int STREAM_SYSTEM

Since: API Level 1

The audio stream for system sounds

Constant Value: 1 (0x00000001)

public static final int STREAM_VOICE_CALL

Since: API Level 1

The audio stream for phone calls

Constant Value: 0 (0x00000000)

public static final int USE_DEFAULT_STREAM_TYPE

Since: API Level 1

Suggests using the default stream type. This may not be used in all places a stream type is needed.

Constant Value: -2147483648 (0x80000000)

public static final String VIBRATE_SETTING_CHANGED_ACTION

Since: API Level 1

Broadcast intent action indicating that the vibrate setting has changed. Includes the vibrate type and its new setting.

Constant Value: "android.media.VIBRATE_SETTING_CHANGED"

public static final int VIBRATE_SETTING_OFF

Since: API Level 1

Vibrate setting that suggests to never vibrate.

Constant Value: 0 (0x00000000)

public static final int VIBRATE_SETTING_ON

Since: API Level 1

Vibrate setting that suggests to vibrate when possible.

Constant Value: 1 (0x00000001)

public static final int VIBRATE_SETTING_ONLY_SILENT

Since: API Level 1

Vibrate setting that suggests to only vibrate when in the vibrate ringer mode.

Constant Value: 2 (0x00000002)

public static final int VIBRATE_TYPE_NOTIFICATION

Since: API Level 1

Vibrate type that corresponds to notifications.

Constant Value: 1 (0x00000001)

public static final int VIBRATE_TYPE_RINGER

Since: API Level 1

Vibrate type that corresponds to the ringer.

Constant Value: 0 (0x00000000)

Public Methods

public int abandonAudioFocus (AudioManager.OnAudioFocusChangeListener l)

Since: API Level 8

Abandon audio focus. Causes the previous focus owner, if any, to receive focus.

Parameters
l the listener with which focus was requested.

public void adjustStreamVolume (int streamType, int direction, int flags)

Since: API Level 1

Adjusts the volume of a particular stream by one step in a direction.

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

Parameters
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.

public void adjustSuggestedStreamVolume (int direction, int suggestedStreamType, int flags)

Since: API Level 1

Adjusts the volume of the most relevant stream, or the given fallback stream.

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

Parameters
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.

public void adjustVolume (int direction, int flags)

Since: API Level 1

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.

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

Parameters
direction The direction to adjust the volume. One of ADJUST_LOWER, ADJUST_RAISE, or ADJUST_SAME.
flags One or more flags.

public int getMode ()

Since: API Level 1

Returns the current audio mode.

Returns
  • the current audio mode (NORMAL, RINGTONE, or IN_CALL). Returns the current current audio state from the HAL.

public String getParameters (String keys)

Since: API Level 5

Sets a varaible number of parameter values to audio hardware.

Parameters
keys list of parameters
Returns
  • list of parameters key value pairs in the form: key1=value1;key2=value2;...

public int getRingerMode ()

Since: API Level 1

Returns the current ringtone mode.

Returns

public int getRouting (int mode)

Since: API Level 1

This method is deprecated.
Do not query audio routing directly, use isSpeakerphoneOn(), isBluetoothScoOn(), isBluetoothA2dpOn() and isWiredHeadsetOn() methods instead.

Returns the current audio routing bit vector for a specified mode.

Parameters
mode audio mode to get route (e.g., MODE_RINGTONE)
Returns
  • an audio route bit vector that can be compared with ROUTE_xxx bits

public int getStreamMaxVolume (int streamType)

Since: API Level 1

Returns the maximum volume index for a particular stream.

Parameters
streamType The stream type whose maximum volume index is returned.
Returns
  • The maximum valid volume index for the stream.

public int getStreamVolume (int streamType)

Since: API Level 1

Returns the current volume index for a particular stream.

Parameters
streamType The stream type whose volume index is returned.
Returns
  • The current volume index for the stream.

public int getVibrateSetting (int vibrateType)

Since: API Level 1

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).

Parameters
vibrateType The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER.
Returns

public boolean isBluetoothA2dpOn ()

Since: API Level 3

Checks whether A2DP audio routing to the Bluetooth headset is on or off.

Returns
  • true if A2DP audio is being routed to/from Bluetooth headset; false if otherwise

public boolean isBluetoothScoAvailableOffCall ()

Since: API Level 8

Indicates if current platform supports use of SCO for off call use cases. Application wanted to use bluetooth SCO audio when the phone is not in call must first call thsi method to make sure that the platform supports this feature.

Returns
  • true if bluetooth SCO can be used for audio when not in call false otherwise

public boolean isBluetoothScoOn ()

Since: API Level 1

Checks whether communications use Bluetooth SCO.

Returns
  • true if SCO is used for communications; false if otherwise

public boolean isMicrophoneMute ()

Since: API Level 1

Checks whether the microphone mute is on or off.

Returns
  • true if microphone is muted, false if it's not

public boolean isMusicActive ()

Since: API Level 1

Checks whether any music is active.

Returns
  • true if any music tracks are active.

public boolean isSpeakerphoneOn ()

Since: API Level 1

Checks whether the speakerphone is on or off.

Returns
  • true if speakerphone is on, false if it's off

public boolean isWiredHeadsetOn ()

Since: API Level 5

Checks whether audio routing to the wired headset is on or off.

Returns
  • true if audio is being routed to/from wired headset; false if otherwise

public void loadSoundEffects ()

Since: API Level 1

Load Sound effects. This method must be called when sound effects are enabled.

public void playSoundEffect (int effectType, float volume)

Since: API Level 3

Plays a sound effect (Key clicks, lid open/close...)

Parameters
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. The volume value is a raw scalar so UI controls should be scaled logarithmically. If a volume of -1 is specified, the AudioManager.STREAM_MUSIC stream volume minus 3dB will be used. NOTE: This version is for applications that have their own settings panel for enabling and controlling volume.

public void playSoundEffect (int effectType)

Since: API Level 1

Plays a sound effect (Key clicks, lid open/close...)

Parameters
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.

public void registerMediaButtonEventReceiver (ComponentName eventReceiver)

Since: API Level 8

Register a component to be the sole receiver of MEDIA_BUTTON intents.

Parameters
eventReceiver identifier of a BroadcastReceiver that will receive the media button intent. This broadcast receiver must be declared in the application manifest.

public int requestAudioFocus (AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint)

Since: API Level 8

Request audio focus. Send a request to obtain the audio focus

Parameters
l the listener to be notified of audio focus changes
streamType the main audio stream type affected by the focus request
durationHint use AUDIOFOCUS_GAIN_TRANSIENT to indicate this focus request is temporary, and focus will be abandonned shortly. Examples of transient requests are for the playback of driving directions, or notifications sounds. Use AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK to indicate also that it's ok for the previous focus owner to keep playing if it ducks its audio output. Use AUDIOFOCUS_GAIN for a focus request of unknown duration such as the playback of a song or a video.

public void setBluetoothA2dpOn (boolean on)

Since: API Level 3

This method is deprecated.
Do not use.

Parameters
on set true to route A2DP audio to/from Bluetooth headset; false disable A2DP audio

public void setBluetoothScoOn (boolean on)

Since: API Level 1

Request use of Bluetooth SCO headset for communications.

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

Parameters
on set true to use bluetooth SCO for communications; false to not use bluetooth SCO for communications

public void setMicrophoneMute (boolean on)

Since: API Level 1

Sets the microphone mute on or off.

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

Parameters
on set true to mute the microphone; false to turn mute off

public void setMode (int mode)

Since: API Level 1

Sets the audio mode.

The audio mode encompasses audio routing AND the behavior of the telephony layer. Therefore this method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application. In particular, the MODE_IN_CALL mode should only be used by the telephony application when it places a phone call, as it will cause signals from the radio layer to feed the platform mixer.

Parameters
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.

public void setParameters (String keyValuePairs)

Since: API Level 5

Sets a variable number of parameter values to audio hardware.

Parameters
keyValuePairs list of parameters key value pairs in the form: key1=value1;key2=value2;...

public void setRingerMode (int ringerMode)

Since: API Level 1

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.

Parameters
ringerMode The ringer mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE.
See Also

public void setRouting (int mode, int routes, int mask)

Since: API Level 1

This method is deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.

Sets the audio routing for a specified mode

Parameters
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

public void setSpeakerphoneOn (boolean on)

Since: API Level 1

Sets the speakerphone on or off.

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

Parameters
on set true to turn on speakerphone; false to turn it off

public void setStreamMute (int streamType, boolean state)

Since: API Level 1

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.

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

Parameters
streamType The stream to be muted/unmuted.
state The required mute state: true for mute ON, false for mute OFF

public void setStreamSolo (int streamType, boolean state)

Since: API Level 1

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.

Parameters
streamType The stream to be soloed/unsoloed.
state The required solo state: true for solo ON, false for solo OFF

public void setStreamVolume (int streamType, int index, int flags)

Since: API Level 1

Sets the volume index for a particular stream.

Parameters
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.

public void setVibrateSetting (int vibrateType, int vibrateSetting)

Since: API Level 1

Sets the setting for when the vibrate type should vibrate.

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

Parameters
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.

public void setWiredHeadsetOn (boolean on)

Since: API Level 5

This method is deprecated.
Do not use.

Sets audio routing to the wired headset on or off.

Parameters
on set true to route audio to/from wired headset; false disable wired headset audio

public boolean shouldVibrate (int vibrateType)

Since: API Level 1

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.

Parameters
vibrateType The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER.
Returns
  • Whether the type should vibrate at the instant this method is called.

public void startBluetoothSco ()

Since: API Level 8

Start bluetooth SCO audio connection.

Requires Permission: MODIFY_AUDIO_SETTINGS.

This method can be used by applications wanting to send and received audio to/from a bluetooth SCO headset while the phone is not in call.

As the SCO connection establishment can take several seconds, applications should not rely on the connection to be available when the method returns but instead register to receive the intent ACTION_SCO_AUDIO_STATE_CHANGED and wait for the state to be SCO_AUDIO_STATE_CONNECTED.

As the connection is not guaranteed to succeed, applications must wait for this intent with a timeout.

When finished with the SCO connection or if the establishment times out, the application must call stopBluetoothSco() to clear the request and turn down the bluetooth connection.

Even if a SCO connection is established, the following restrictions apply on audio output streams so that they can be routed to SCO headset: - the stream type must be STREAM_VOICE_CALL - the format must be mono - the sampling must be 16kHz or 8kHz

The following restrictions apply on input streams: - the format must be mono - the sampling must be 8kHz

Note that the phone application always has the priority on the usage of the SCO connection for telephony. If this method is called while the phone is in call it will be ignored. Similarly, if a call is received or sent while an application is using the SCO connection, the connection will be lost for the application and NOT returned automatically when the call ends.

public void stopBluetoothSco ()

Since: API Level 8

Stop bluetooth SCO audio connection.

Requires Permission: MODIFY_AUDIO_SETTINGS.

This method must be called by applications having requested the use of bluetooth SCO audio with startBluetoothSco() when finished with the SCO connection or if the establishment times out.

public void unloadSoundEffects ()

Since: API Level 1

Unload Sound effects. This method can be called to free some memory when sound effects are disabled.

public void unregisterMediaButtonEventReceiver (ComponentName eventReceiver)

Since: API Level 8

Unregister the receiver of MEDIA_BUTTON intents.

Parameters
eventReceiver identifier of a BroadcastReceiver that was registered with registerMediaButtonEventReceiver(ComponentName).