Android APIs
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_HDMI_AUDIO_PLUG Broadcast Action: A sticky broadcast indicating an HDMI cable was plugged or unplugged.
String ACTION_HEADSET_PLUG Broadcast Action: Wired Headset plugged in or unplugged.
String ACTION_SCO_AUDIO_STATE_CHANGED This constant was deprecated in API level 14. Use ACTION_SCO_AUDIO_STATE_UPDATED instead
String ACTION_SCO_AUDIO_STATE_UPDATED Sticky broadcast intent action indicating that the bluetoooth SCO audio connection state has been updated.
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_EXCLUSIVE Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, during which no other applications, or system components, should play anything.
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.
int AUDIO_SESSION_ID_GENERATE A special audio session ID to indicate that the audio session ID isn't known and the framework should generate a new value.
int ERROR A default error code.
int ERROR_DEAD_OBJECT An error code indicating that the object reporting it is no longer valid and needs to be recreated.
String EXTRA_AUDIO_PLUG_STATE Extra used in ACTION_HDMI_AUDIO_PLUG to communicate whether HDMI is plugged in or unplugged.
String EXTRA_ENCODINGS Extra used in ACTION_HDMI_AUDIO_PLUG to define the audio encodings supported by the connected HDMI device.
String EXTRA_MAX_CHANNEL_COUNT Extra used in ACTION_HDMI_AUDIO_PLUG to define the maximum number of channels supported by the HDMI device.
String EXTRA_RINGER_MODE The new ringer mode.
String EXTRA_SCO_AUDIO_PREVIOUS_STATE Extra for intent ACTION_SCO_AUDIO_STATE_UPDATED containing the previous bluetooth SCO connection state.
String EXTRA_SCO_AUDIO_STATE Extra for intent ACTION_SCO_AUDIO_STATE_CHANGED or ACTION_SCO_AUDIO_STATE_UPDATED containing the new bluetooth SCO connection state.
String EXTRA_VIBRATE_SETTING This constant was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode and listen to RINGER_MODE_CHANGED_ACTION instead.
String EXTRA_VIBRATE_TYPE This constant was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode and listen to RINGER_MODE_CHANGED_ACTION instead.
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_INVALID Invalid 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_IN_COMMUNICATION In communication 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 was deprecated in API level 3. Use AudioSystem.getNumStreamTypes() instead
String PROPERTY_OUTPUT_FRAMES_PER_BUFFER Used as a key for getProperty(String) to request the native or optimal output buffer size for this device's primary output stream, in decimal PCM frames.
String PROPERTY_OUTPUT_SAMPLE_RATE Used as a key for getProperty(String) to request the native or optimal output sample rate for this device's primary output stream, in decimal Hz.
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 was deprecated in API level 5. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_BLUETOOTH This constant was deprecated in API level 3. use ROUTE_BLUETOOTH_SCODo not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_BLUETOOTH_A2DP This constant was deprecated in API level 5. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_BLUETOOTH_SCO This constant was deprecated in API level 5. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_EARPIECE This constant was deprecated in API level 5. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_HEADSET This constant was deprecated in API level 5. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int ROUTE_SPEAKER This constant was deprecated in API level 5. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
int SCO_AUDIO_STATE_CONNECTED Value for extra EXTRA_SCO_AUDIO_STATE or EXTRA_SCO_AUDIO_PREVIOUS_STATE indicating that the SCO audio channel is established
int SCO_AUDIO_STATE_CONNECTING Value for extra EXTRA_SCO_AUDIO_STATE or EXTRA_SCO_AUDIO_PREVIOUS_STATE indicating that the SCO audio channel is being established
int SCO_AUDIO_STATE_DISCONNECTED Value for extra EXTRA_SCO_AUDIO_STATE or EXTRA_SCO_AUDIO_PREVIOUS_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 This constant was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode and listen to RINGER_MODE_CHANGED_ACTION instead.
int VIBRATE_SETTING_OFF This constant was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
int VIBRATE_SETTING_ON This constant was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
int VIBRATE_SETTING_ONLY_SILENT This constant was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
int VIBRATE_TYPE_NOTIFICATION This constant was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
int VIBRATE_TYPE_RINGER This constant was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
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.
void dispatchMediaKeyEvent(KeyEvent keyEvent)
Sends a simulated key event for a media button.
int generateAudioSessionId()
Return a new audio session identifier not associated with any player or effect.
int getMode()
Returns the current audio mode.
String getParameters(String keys)
Gets a variable number of parameter values from audio hardware.
String getProperty(String key)
Returns the value of the property with the specified key.
int getRingerMode()
Returns the current ringtone mode.
int getRouting(int mode)
This method was deprecated in API level 4. 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)
This method was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
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 isVolumeFixed()
Indicates if the device implements a fixed volume policy.
boolean isWiredHeadsetOn()
This method was deprecated in API level 14. Use only to check is a headset is connected or not.
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(PendingIntent eventReceiver)
This method was deprecated in API level 21. Use setMediaButtonReceiver(PendingIntent) instead.
void registerMediaButtonEventReceiver(ComponentName eventReceiver)
This method was deprecated in API level 21. Use setMediaButtonReceiver(PendingIntent) instead.
void registerRemoteControlClient(RemoteControlClient rcClient)
This method was deprecated in API level 21. Use MediaSession instead.
boolean registerRemoteController(RemoteController rctlr)
int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint)
Request audio focus.
void setBluetoothA2dpOn(boolean on)
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 was deprecated in API level 4. 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)
This method was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
void setWiredHeadsetOn(boolean on)
This method was deprecated in API level 5. Do not use.
boolean shouldVibrate(int vibrateType)
This method was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
void startBluetoothSco()
Start bluetooth SCO audio connection.
void stopBluetoothSco()
Stop bluetooth SCO audio connection.
void unloadSoundEffects()
Unload Sound effects.
void unregisterMediaButtonEventReceiver(ComponentName eventReceiver)
This method was deprecated in API level 21. Use MediaSession instead.
void unregisterMediaButtonEventReceiver(PendingIntent eventReceiver)
This method was deprecated in API level 21. Use MediaSession instead.
void unregisterRemoteControlClient(RemoteControlClient rcClient)
This method was deprecated in API level 21. Use MediaSession instead.
void unregisterRemoteController(RemoteController rctlr)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_AUDIO_BECOMING_NOISY

Added in 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_HDMI_AUDIO_PLUG

Added in API level 21

Broadcast Action: A sticky broadcast indicating an HDMI cable was plugged or unplugged. The intent will have the following extra values: EXTRA_AUDIO_PLUG_STATE, EXTRA_MAX_CHANNEL_COUNT, EXTRA_ENCODINGS.

It can only be received by explicitly registering for it with registerReceiver(BroadcastReceiver, IntentFilter).

Constant Value: "android.media.action.HDMI_AUDIO_PLUG"

public static final String ACTION_HEADSET_PLUG

Added in API level 21

Broadcast Action: Wired Headset plugged in or unplugged. You cannot receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver().

The intent will have the following extra values:

  • state - 0 for unplugged, 1 for plugged.
  • name - Headset type, human readable string
  • microphone - 1 if headset has a microphone, 0 otherwise

Constant Value: "android.intent.action.HEADSET_PLUG"

public static final String ACTION_SCO_AUDIO_STATE_CHANGED

Added in API level 8

This constant was deprecated in API level 14.
Use ACTION_SCO_AUDIO_STATE_UPDATED instead

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 String ACTION_SCO_AUDIO_STATE_UPDATED

Added in API level 14

Sticky broadcast intent action indicating that the bluetoooth SCO audio connection state has been updated.

This intent has two extras:

EXTRA_SCO_AUDIO_STATE or EXTRA_SCO_AUDIO_PREVIOUS_STATE can be any of:

Constant Value: "android.media.ACTION_SCO_AUDIO_STATE_UPDATED"

public static final int ADJUST_LOWER

Added in API level 1

Decrease the ringer volume.

Constant Value: -1 (0xffffffff)

public static final int ADJUST_RAISE

Added in API level 1

Increase the ringer volume.

Constant Value: 1 (0x00000001)

public static final int ADJUST_SAME

Added in 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

Added in 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

Added in 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_EXCLUSIVE

Added in API level 19

Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, during which no other applications, or system components, should play anything. Examples of exclusive and transient audio focus requests are voice memo recording and speech recognition, during which the system shouldn't play any notifications, and media playback should have paused.

Constant Value: 4 (0x00000004)

public static final int AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK

Added in 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

Added in 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

Added in 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

Added in 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

Added in API level 8

A failed focus change request.

Constant Value: 0 (0x00000000)

public static final int AUDIOFOCUS_REQUEST_GRANTED

Added in API level 8

A successful focus change request.

Constant Value: 1 (0x00000001)

public static final int AUDIO_SESSION_ID_GENERATE

Added in API level 21

A special audio session ID to indicate that the audio session ID isn't known and the framework should generate a new value. This can be used when building a new AudioTrack instance with AudioTrack(AudioAttributes, AudioFormat, int, int, int).

Constant Value: 0 (0x00000000)

public static final int ERROR

Added in API level 21

A default error code.

Constant Value: -1 (0xffffffff)

public static final int ERROR_DEAD_OBJECT

Added in API level 21

An error code indicating that the object reporting it is no longer valid and needs to be recreated.

Constant Value: -6 (0xfffffffa)

public static final String EXTRA_AUDIO_PLUG_STATE

Added in API level 21

Extra used in ACTION_HDMI_AUDIO_PLUG to communicate whether HDMI is plugged in or unplugged. An integer value of 1 indicates a plugged-in state, 0 is unplugged.

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

public static final String EXTRA_ENCODINGS

Added in API level 21

Extra used in ACTION_HDMI_AUDIO_PLUG to define the audio encodings supported by the connected HDMI device. The corresponding array of encoding values is only available when the device is plugged in (as expressed by EXTRA_AUDIO_PLUG_STATE). Encoding values are defined in AudioFormat (for instance see ENCODING_PCM_16BIT). Use getIntArrayExtra(String) to retrieve the encoding values.

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

public static final String EXTRA_MAX_CHANNEL_COUNT

Added in API level 21

Extra used in ACTION_HDMI_AUDIO_PLUG to define the maximum number of channels supported by the HDMI device. The corresponding integer value is only available when the device is plugged in (as expressed by EXTRA_AUDIO_PLUG_STATE).

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

public static final String EXTRA_RINGER_MODE

Added in API level 1

The new ringer mode.

Constant Value: "android.media.EXTRA_RINGER_MODE"

public static final String EXTRA_SCO_AUDIO_PREVIOUS_STATE

Added in API level 14

Extra for intent ACTION_SCO_AUDIO_STATE_UPDATED containing the previous bluetooth SCO connection state.

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

public static final String EXTRA_SCO_AUDIO_STATE

Added in API level 8

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

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

public static final String EXTRA_VIBRATE_SETTING

Added in API level 1

This constant was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode and listen to RINGER_MODE_CHANGED_ACTION instead.

The new vibrate setting for a particular type.

Constant Value: "android.media.EXTRA_VIBRATE_SETTING"

public static final String EXTRA_VIBRATE_TYPE

Added in API level 1

This constant was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode and listen to RINGER_MODE_CHANGED_ACTION instead.

The vibrate type whose setting has changed.

Constant Value: "android.media.EXTRA_VIBRATE_TYPE"

public static final int FLAG_ALLOW_RINGER_MODES

Added in 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

Added in 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

Added in 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

Added in API level 1

Show a toast containing the current volume.

Constant Value: 1 (0x00000001)

public static final int FLAG_VIBRATE

Added in 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

Added in API level 1

Focus has moved down

Constant Value: 2 (0x00000002)

public static final int FX_FOCUS_NAVIGATION_LEFT

Added in API level 1

Focus has moved left

Constant Value: 3 (0x00000003)

public static final int FX_FOCUS_NAVIGATION_RIGHT

Added in API level 1

Focus has moved right

Constant Value: 4 (0x00000004)

public static final int FX_FOCUS_NAVIGATION_UP

Added in API level 1

Focus has moved up

Constant Value: 1 (0x00000001)

public static final int FX_KEYPRESS_DELETE

Added in API level 3

IME delete keypress sound

Constant Value: 7 (0x00000007)

public static final int FX_KEYPRESS_INVALID

Added in API level 19

Invalid keypress sound

Constant Value: 9 (0x00000009)

public static final int FX_KEYPRESS_RETURN

Added in API level 3

IME return_keypress sound

Constant Value: 8 (0x00000008)

public static final int FX_KEYPRESS_SPACEBAR

Added in API level 3

IME spacebar keypress sound

Constant Value: 6 (0x00000006)

public static final int FX_KEYPRESS_STANDARD

Added in API level 3

IME standard keypress sound

Constant Value: 5 (0x00000005)

public static final int FX_KEY_CLICK

Added in API level 1

Keyboard and direction pad click sound

Constant Value: 0 (0x00000000)

public static final int MODE_CURRENT

Added in API level 1

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

Constant Value: -1 (0xffffffff)

public static final int MODE_INVALID

Added in API level 1

Invalid audio mode.

Constant Value: -2 (0xfffffffe)

public static final int MODE_IN_CALL

Added in API level 1

In call audio mode. A telephony call is established.

Constant Value: 2 (0x00000002)

public static final int MODE_IN_COMMUNICATION

Added in API level 11

In communication audio mode. An audio/video chat or VoIP call is established.

Constant Value: 3 (0x00000003)

public static final int MODE_NORMAL

Added in API level 1

Normal audio mode: not ringing and no call established.

Constant Value: 0 (0x00000000)

public static final int MODE_RINGTONE

Added in API level 1

Ringing audio mode. An incoming is being signaled.

Constant Value: 1 (0x00000001)

public static final int NUM_STREAMS

Added in API level 1

This constant was deprecated in API level 3.
Use AudioSystem.getNumStreamTypes() instead

Constant Value: 5 (0x00000005)

public static final String PROPERTY_OUTPUT_FRAMES_PER_BUFFER

Added in API level 17

Used as a key for getProperty(String) to request the native or optimal output buffer size for this device's primary output stream, in decimal PCM frames.

Constant Value: "android.media.property.OUTPUT_FRAMES_PER_BUFFER"

public static final String PROPERTY_OUTPUT_SAMPLE_RATE

Added in API level 17

Used as a key for getProperty(String) to request the native or optimal output sample rate for this device's primary output stream, in decimal Hz.

Constant Value: "android.media.property.OUTPUT_SAMPLE_RATE"

public static final String RINGER_MODE_CHANGED_ACTION

Added in 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

Added in 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

Added in 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

Added in 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

Added in API level 1

This constant was deprecated in API level 5.
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

Added in API level 1

This constant was deprecated in API level 3.
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

Added in API level 3

This constant was deprecated in API level 5.
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

Added in API level 3

This constant was deprecated in API level 5.
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

Added in API level 1

This constant was deprecated in API level 5.
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

Added in API level 1

This constant was deprecated in API level 5.
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

Added in API level 1

This constant was deprecated in API level 5.
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

Added in API level 8

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

Constant Value: 1 (0x00000001)

public static final int SCO_AUDIO_STATE_CONNECTING

Added in API level 14

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

Constant Value: 2 (0x00000002)

public static final int SCO_AUDIO_STATE_DISCONNECTED

Added in API level 8

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

Constant Value: 0 (0x00000000)

public static final int SCO_AUDIO_STATE_ERROR

Added in 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

Added in API level 1

The audio stream for alarms

Constant Value: 4 (0x00000004)

public static final int STREAM_DTMF

Added in API level 5

The audio stream for DTMF Tones

Constant Value: 8 (0x00000008)

public static final int STREAM_MUSIC

Added in API level 1

The audio stream for music playback

Constant Value: 3 (0x00000003)

public static final int STREAM_NOTIFICATION

Added in API level 3

The audio stream for notifications

Constant Value: 5 (0x00000005)

public static final int STREAM_RING

Added in API level 1

The audio stream for the phone ring

Constant Value: 2 (0x00000002)

public static final int STREAM_SYSTEM

Added in API level 1

The audio stream for system sounds

Constant Value: 1 (0x00000001)

public static final int STREAM_VOICE_CALL

Added in API level 1

The audio stream for phone calls

Constant Value: 0 (0x00000000)

public static final int USE_DEFAULT_STREAM_TYPE

Added in 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

Added in API level 1

This constant was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode and listen to RINGER_MODE_CHANGED_ACTION instead.

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

Added in API level 1

This constant was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

Vibrate setting that suggests to never vibrate.

Constant Value: 0 (0x00000000)

public static final int VIBRATE_SETTING_ON

Added in API level 1

This constant was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

Vibrate setting that suggests to vibrate when possible.

Constant Value: 1 (0x00000001)

public static final int VIBRATE_SETTING_ONLY_SILENT

Added in API level 1

This constant was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

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

Constant Value: 2 (0x00000002)

public static final int VIBRATE_TYPE_NOTIFICATION

Added in API level 1

This constant was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

Vibrate type that corresponds to notifications.

Constant Value: 1 (0x00000001)

public static final int VIBRATE_TYPE_RINGER

Added in API level 1

This constant was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

Vibrate type that corresponds to the ringer.

Constant Value: 0 (0x00000000)

Public Methods

public int abandonAudioFocus (AudioManager.OnAudioFocusChangeListener l)

Added in 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)

Added in 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)

Added in 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.

This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().

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)

Added in 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.

This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().

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

public void dispatchMediaKeyEvent (KeyEvent keyEvent)

Added in API level 19

Sends a simulated key event for a media button. To simulate a key press, you must first send a KeyEvent built with a ACTION_DOWN action, then another event with the ACTION_UP action.

The key event will be sent to the current media key event consumer which registered with registerMediaButtonEventReceiver(PendingIntent).

public int generateAudioSessionId ()

Added in API level 21

Return a new audio session identifier not associated with any player or effect. An audio session identifier is a system wide unique identifier for a set of audio streams (one or more mixed together).

The primary use of the audio session ID is to associate audio effects to audio players, such as MediaPlayer or AudioTrack: all audio effects sharing the same audio session ID will be applied to the mixed audio content of the players that share the same audio session.

This method can for instance be used when creating one of the AudioEffect objects to define the audio session of the effect, or to specify a session for a speech synthesis utterance in TextToSpeech.Engine.

Returns
  • a new unclaimed and unused audio session identifier, or ERROR when the system failed to generate a new session, a condition in which audio playback or recording will subsequently fail as well.

public int getMode ()

Added in API level 1

Returns the current audio mode.

Returns

public String getParameters (String keys)

Added in API level 5

Gets a variable number of parameter values from audio hardware.

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

public String getProperty (String key)

Added in API level 17

Returns the value of the property with the specified key.

Parameters
key One of the strings corresponding to a property key: either PROPERTY_OUTPUT_SAMPLE_RATE or PROPERTY_OUTPUT_FRAMES_PER_BUFFER
Returns
  • A string representing the associated value for that property key, or null if there is no value for that key.

public int getRingerMode ()

Added in API level 1

Returns the current ringtone mode.

Returns

public int getRouting (int mode)

Added in API level 1

This method was deprecated in API level 4.
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)

Added in 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)

Added in 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)

Added in API level 1

This method was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

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

Added in 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 ()

Added in 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 this 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 ()

Added in API level 1

Checks whether communications use Bluetooth SCO.

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

public boolean isMicrophoneMute ()

Added in 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 ()

Added in API level 1

Checks whether any music is active.

Returns
  • true if any music tracks are active.

public boolean isSpeakerphoneOn ()

Added in API level 1

Checks whether the speakerphone is on or off.

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

public boolean isVolumeFixed ()

Added in API level 21

Indicates if the device implements a fixed volume policy.

Some devices may not have volume control and may operate at a fixed volume, and may not enable muting or changing the volume of audio streams. This method will return true on such devices.

The following APIs have no effect when volume is fixed:

public boolean isWiredHeadsetOn ()

Added in API level 5

This method was deprecated in API level 14.
Use only to check is a headset is connected or not.

Checks whether a wired headset is connected or not.

This is not a valid indication that audio playback is actually over the wired headset as audio routing depends on other conditions.

Returns
  • true if a wired headset is connected. false if otherwise

public void loadSoundEffects ()

Added in API level 1

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

public void playSoundEffect (int effectType, float volume)

Added in 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, FX_KEYPRESS_INVALID,
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)

Added in 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, FX_KEYPRESS_INVALID, NOTE: This version uses the UI settings to determine whether sounds are heard or not.

public void registerMediaButtonEventReceiver (PendingIntent eventReceiver)

Added in API level 18

This method was deprecated in API level 21.
Use setMediaButtonReceiver(PendingIntent) instead.

Register a component to be the sole receiver of MEDIA_BUTTON intents. This is like registerMediaButtonEventReceiver(android.content.ComponentName), but allows the buttons to go to any PendingIntent. Note that you should only use this form if you know you will continue running for the full time until unregistering the PendingIntent.

Parameters
eventReceiver target that will receive media button intents. The PendingIntent will be sent an ACTION_MEDIA_BUTTON event when a media button action occurs, with EXTRA_KEY_EVENT added and holding the key code of the media button that was pressed.

public void registerMediaButtonEventReceiver (ComponentName eventReceiver)

Added in API level 8

This method was deprecated in API level 21.
Use setMediaButtonReceiver(PendingIntent) instead.

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. The package of the component must match that of the context you're registering from.

public void registerRemoteControlClient (RemoteControlClient rcClient)

Added in API level 14

This method was deprecated in API level 21.
Use MediaSession instead.

Registers the remote control client for providing information to display on the remote controls.

Parameters
rcClient The remote control client from which remote controls will receive information to display.

public boolean registerRemoteController (RemoteController rctlr)

Added in API level 19

This method was deprecated in API level 21.
Use addOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener, ComponentName) and MediaController instead.

Registers a RemoteController instance for it to receive media metadata updates and playback state information from applications using RemoteControlClient, and control their playback.

Registration requires the RemoteController.OnClientUpdateListener listener to be one of the enabled notification listeners (see NotificationListenerService).

Parameters
rctlr the object to register.
Returns
  • true if the RemoteController was successfully registered, false if an error occurred, due to an internal system error, or insufficient permissions.

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

Added in 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. Alternatively use AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE for a temporary request that benefits from the system not playing disruptive sounds like notifications, for usecases such as voice memo recording, or speech recognition. 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)

Added in API level 3

This method was deprecated in API level 5.
Do not use.

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

public void setBluetoothScoOn (boolean on)

Added in 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)

Added in 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)

Added in 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 (MODE_NORMAL, MODE_RINGTONE, MODE_IN_CALL or MODE_IN_COMMUNICATION). Informs the HAL about the current audio state so that it can route the audio appropriately.

public void setParameters (String keyValuePairs)

Added in 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)

Added in 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.

This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().

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

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

Added in API level 1

This method was deprecated in API level 4.
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)

Added in 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)

Added in 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.

This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().

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

public void setStreamSolo (int streamType, boolean state)

Added in 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.

This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().

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

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

Added in API level 1

Sets the volume index for a particular stream.

This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().

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)

Added in API level 1

This method was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

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)

Added in API level 5

This method was deprecated in API level 5.
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)

Added in API level 1

This method was deprecated in API level 16.
Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

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

Added in 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_UPDATED and wait for the state to be SCO_AUDIO_STATE_CONNECTED.

As the ACTION_SCO_AUDIO_STATE_UPDATED intent is sticky, the application can check the SCO audio state before calling startBluetoothSco() by reading the intent returned by the receiver registration. If the state is already CONNECTED, no state change will be received via the intent after calling startBluetoothSco(). It is however useful to call startBluetoothSco() so that the connection stays active in case the current initiator stops the connection.

Unless the connection is already active as described above, the state will always transition from DISCONNECTED to CONNECTING and then either to CONNECTED if the connection succeeds or back to DISCONNECTED if the connection fails (e.g no headset is connected).

When finished with the SCO connection or if the establishment fails, 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.

NOTE: up to and including API version JELLY_BEAN_MR1, this method initiates a virtual voice call to the bluetooth headset. After API version JELLY_BEAN_MR2 only a raw SCO audio connection is established.

public void stopBluetoothSco ()

Added in 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 connection fails.

public void unloadSoundEffects ()

Added in 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)

Added in API level 8

This method was deprecated in API level 21.
Use MediaSession instead.

Unregister the receiver of MEDIA_BUTTON intents.

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

public void unregisterMediaButtonEventReceiver (PendingIntent eventReceiver)

Added in API level 18

This method was deprecated in API level 21.
Use MediaSession instead.

Unregister the receiver of MEDIA_BUTTON intents.

Parameters
eventReceiver same PendingIntent that was registed with registerMediaButtonEventReceiver(PendingIntent).

public void unregisterRemoteControlClient (RemoteControlClient rcClient)

Added in API level 14

This method was deprecated in API level 21.
Use MediaSession instead.

Unregisters the remote control client that was providing information to display on the remote controls.

Parameters
rcClient The remote control client to unregister.

public void unregisterRemoteController (RemoteController rctlr)

Added in API level 19

This method was deprecated in API level 21.
Use removeOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener) instead.

Unregisters a RemoteController, causing it to no longer receive media metadata and playback state information, and no longer be capable of controlling playback.

Parameters
rctlr the object to unregister.