# Print output for @column tags ?> AudioManager - Android SDK | Android Developers

Most visited

Recently visited

AudioManager

public class AudioManager
extends Object

java.lang.Object
   ↳ android.media.AudioManager


AudioManager provides access to volume and ringer mode control.

Summary

Nested classes

class AudioManager.AudioPlaybackCallback

Interface for receiving update notifications about the playback activity on the system. 

class AudioManager.AudioRecordingCallback

Interface for receiving update notifications about the recording configuration. 

interface AudioManager.OnAudioFocusChangeListener

Interface definition for a callback to be invoked when the audio focus of the system is updated. 

interface AudioManager.OnCommunicationDeviceChangedListener

Listener registered by client to be notified upon communication audio device change. 

interface AudioManager.OnModeChangedListener

Interface definition of a callback that is notified when the audio mode changes 

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_MICROPHONE_MUTE_CHANGED

Broadcast Action: microphone muting state changed.

String ACTION_SCO_AUDIO_STATE_CHANGED

This constant is deprecated. Use ACTION_SCO_AUDIO_STATE_UPDATED instead

String ACTION_SCO_AUDIO_STATE_UPDATED

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

String ACTION_SPEAKERPHONE_STATE_CHANGED

Broadcast Action: speakerphone state changed.

int ADJUST_LOWER

Decrease the ringer volume.

int ADJUST_MUTE

Mute the volume.

int ADJUST_RAISE

Increase the ringer volume.

int ADJUST_SAME

Maintain the previous ringer volume.

int ADJUST_TOGGLE_MUTE

Toggle the mute state.

int ADJUST_UNMUTE

Unmute the 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_NONE

Used to indicate no audio focus has been gained or lost, or requested.

int AUDIOFOCUS_REQUEST_DELAYED

A focus change request whose granting is delayed: the request was successful, but the requester will only be granted audio focus once the condition that prevented immediate granting has ended.

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 ENCODED_SURROUND_OUTPUT_ALWAYS

The surround sound formats are ALWAYS available, even if they are not detected by the hardware.

int ENCODED_SURROUND_OUTPUT_AUTO

The surround sound formats are available for use if they are detected.

int ENCODED_SURROUND_OUTPUT_MANUAL

Surround sound formats are available according to the choice of user, even if they are not detected by the hardware.

int ENCODED_SURROUND_OUTPUT_NEVER

The surround sound formats are NEVER available, even if they are detected by the hardware.

int ENCODED_SURROUND_OUTPUT_UNKNOWN

The mode for surround sound formats is unknown.

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 is deprecated. 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 is deprecated. 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_BACK

Back sound

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 GET_DEVICES_ALL

Specifies to the AudioManager#getDevices(int) method to include both source and sink devices.

int GET_DEVICES_INPUTS

Specifies to the AudioManager#getDevices(int) method to include source (i.e.

int GET_DEVICES_OUTPUTS

Specifies to the AudioManager#getDevices(int) method to include sink (i.e.

int MODE_CALL_SCREENING

Call screening in progress.

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 is deprecated. Do not iterate on volume stream type values.

int PLAYBACK_OFFLOAD_GAPLESS_SUPPORTED

Return value for getPlaybackOffloadSupport(android.media.AudioFormat, android.media.AudioAttributes): offload playback supported with gapless transitions

int PLAYBACK_OFFLOAD_NOT_SUPPORTED

Return value for getPlaybackOffloadSupport(android.media.AudioFormat, android.media.AudioAttributes): offload playback not supported

int PLAYBACK_OFFLOAD_SUPPORTED

Return value for getPlaybackOffloadSupport(android.media.AudioFormat, android.media.AudioAttributes): offload playback supported

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 low latency 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 low latency output stream, in decimal Hz.

String PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED

Used as a key for getProperty(String) to determine if the unprocessed audio source is available and supported with the expected frequency range and level response.

String PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND

Used as a key for getProperty(String) to determine if the default microphone audio source supports near-ultrasound frequencies (range of 18 - 21 kHz).

String PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND

Used as a key for getProperty(String) to determine if the default speaker audio path supports near-ultrasound frequencies (range of 18 - 21 kHz).

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 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_ACCESSIBILITY

Used to identify the volume of audio streams for accessibility prompts

int STREAM_ALARM

Used to identify the volume of audio streams for alarms

int STREAM_DTMF

Used to identify the volume of audio streams for DTMF Tones

int STREAM_MUSIC

Used to identify the volume of audio streams for music playback

int STREAM_NOTIFICATION

Used to identify the volume of audio streams for notifications

int STREAM_RING

Used to identify the volume of audio streams for the phone ring

int STREAM_SYSTEM

Used to identify the volume of audio streams for system sounds

int STREAM_VOICE_CALL

Used to identify the volume of audio streams for phone calls

int USE_DEFAULT_STREAM_TYPE

Suggests using the default stream type.

String VIBRATE_SETTING_CHANGED_ACTION

This constant is deprecated. 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 is deprecated. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

int VIBRATE_SETTING_ON

This constant is deprecated. 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 is deprecated. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

int VIBRATE_TYPE_NOTIFICATION

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

int VIBRATE_TYPE_RINGER

This constant is deprecated. 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)

This method is deprecated. use abandonAudioFocusRequest(android.media.AudioFocusRequest)

int abandonAudioFocusRequest(AudioFocusRequest focusRequest)

Abandon audio focus.

void addOnCommunicationDeviceChangedListener(Executor executor, AudioManager.OnCommunicationDeviceChangedListener listener)

Adds a listener for being notified of changes to the communication audio device.

void addOnModeChangedListener(Executor executor, AudioManager.OnModeChangedListener listener)

Adds a listener to be notified of changes to the audio mode.

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

Cancels previous communication device selection made with setCommunicationDevice(android.media.AudioDeviceInfo).

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.

List<AudioPlaybackConfiguration> getActivePlaybackConfigurations()

Returns the current active audio playback configurations of the device

List<AudioRecordingConfiguration> getActiveRecordingConfigurations()

Returns the current active audio recording configurations of the device.

int getAllowedCapturePolicy()

Return the capture policy.

int getAudioHwSyncForSession(int sessionId)

Retrieves the Hardware A/V synchronization ID corresponding to the given audio session ID.

List<AudioDeviceInfo> getAvailableCommunicationDevices()

Returns a list of audio devices that can be selected for communication use cases via setCommunicationDevice(android.media.AudioDeviceInfo).

AudioDeviceInfo getCommunicationDevice()

Returns currently selected audio device for communication.

AudioDeviceInfo[] getDevices(int flags)

Returns an array of AudioDeviceInfo objects corresponding to the audio devices currently connected to the system and meeting the criteria specified in the flags parameter.

int getEncodedSurroundMode()

Gets the surround sound mode.

List<MicrophoneInfo> getMicrophones()

Returns a list of MicrophoneInfo that corresponds to the characteristics of all available microphones.

int getMode()

Returns the current audio mode.

String getParameters(String keys)

Gets a variable number of parameter values from audio hardware.

static int getPlaybackOffloadSupport(AudioFormat format, AudioAttributes attributes)

Returns whether offloaded playback of an audio format is supported on the device or not and when supported whether gapless transitions are possible or not.

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 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 getStreamMinVolume(int streamType)

Returns the minimum volume index for a particular stream.

int getStreamVolume(int streamType)

Returns the current volume index for a particular stream.

float getStreamVolumeDb(int streamType, int index, int deviceType)

Returns the volume in dB (decibel) for the given stream type at the given volume index, on the given type of audio output device.

int getVibrateSetting(int vibrateType)

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

boolean isBluetoothA2dpOn()

This method is deprecated. Use AudioManager#getDevices(int) instead to list available audio devices.

boolean isBluetoothScoAvailableOffCall()

Indicates if current platform supports use of SCO for off call use cases.

boolean isBluetoothScoOn()

Checks whether communications use Bluetooth SCO.

boolean isCallScreeningModeSupported()

Indicates if the platform supports a special call screening and call monitoring mode.

static boolean isHapticPlaybackSupported()

Return if audio haptic coupled playback is supported or not.

boolean isMicrophoneMute()

Checks whether the microphone mute is on or off.

boolean isMusicActive()

Checks whether any music is active.

static boolean isOffloadedPlaybackSupported(AudioFormat format, AudioAttributes attributes)

Returns whether offloaded playback of an audio format is supported on the device.

boolean isSpeakerphoneOn()

Checks whether the speakerphone is on or off.

boolean isStreamMute(int streamType)

Returns the current mute state for a particular stream.

boolean isSurroundFormatEnabled(int audioFormat)

Gets whether a certain surround format is enabled or not.

boolean isVolumeFixed()

Indicates if the device implements a fixed volume policy.

boolean isWiredHeadsetOn()

This method is deprecated. Use AudioManager#getDevices(int) instead to list available audio devices.

void loadSoundEffects()

Load Sound effects.

void playSoundEffect(int effectType)

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

void playSoundEffect(int effectType, float volume)

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

void registerAudioDeviceCallback(AudioDeviceCallback callback, Handler handler)

Registers an AudioDeviceCallback object to receive notifications of changes to the set of connected audio devices.

void registerAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb, Handler handler)

Register a callback to be notified of audio playback changes through AudioPlaybackCallback

void registerAudioRecordingCallback(AudioManager.AudioRecordingCallback cb, Handler handler)

Register a callback to be notified of audio recording changes through AudioRecordingCallback

void registerMediaButtonEventReceiver(ComponentName eventReceiver)

This method is deprecated. Use MediaSession#setMediaButtonReceiver(PendingIntent) instead.

void registerMediaButtonEventReceiver(PendingIntent eventReceiver)

This method is deprecated. Use MediaSession#setMediaButtonReceiver(PendingIntent) instead.

void registerRemoteControlClient(RemoteControlClient rcClient)

This method is deprecated. Use MediaSession instead.

boolean registerRemoteController(RemoteController rctlr)

This method is deprecated. Use MediaSessionManager#addOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener, ComponentName) and MediaController instead.

void removeOnCommunicationDeviceChangedListener(AudioManager.OnCommunicationDeviceChangedListener listener)

Removes a previously added listener of changes to the communication audio device.

void removeOnModeChangedListener(AudioManager.OnModeChangedListener listener)

Removes a previously added listener for changes to audio mode.

int requestAudioFocus(AudioFocusRequest focusRequest)

Request audio focus.

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

This method is deprecated. use requestAudioFocus(android.media.AudioFocusRequest)

void setAllowedCapturePolicy(int capturePolicy)

Specifies whether the audio played by this app may or may not be captured by other apps or the system.

void setBluetoothA2dpOn(boolean on)

This method is deprecated. Do not use.

void setBluetoothScoOn(boolean on)

Request use of Bluetooth SCO headset for communications.

boolean setCommunicationDevice(AudioDeviceInfo device)

Selects the audio device that should be used for communication use cases, for instance voice or video calls.

boolean setEncodedSurroundMode(int mode)

Sets the surround sound mode.

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)

This method is deprecated. Use adjustStreamVolume(int, int, int) with ADJUST_MUTE or ADJUST_UNMUTE instead.

void setStreamSolo(int streamType, boolean state)

This method is deprecated. Do not use. If you need exclusive audio playback use requestAudioFocus(AudioFocusRequest).

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

Sets the volume index for a particular stream.

boolean setSurroundFormatEnabled(int audioFormat, boolean enabled)

Sets and persists a certain surround format as enabled or not.

void setVibrateSetting(int vibrateType, int vibrateSetting)

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

void setWiredHeadsetOn(boolean on)

This method is deprecated. Do not use.

boolean shouldVibrate(int vibrateType)

This method is deprecated. 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 unregisterAudioDeviceCallback(AudioDeviceCallback callback)

Unregisters an AudioDeviceCallback object which has been previously registered to receive notifications of changes to the set of connected audio devices.

void unregisterAudioPlaybackCallback(AudioManager.AudioPlaybackCallback cb)

Unregister an audio playback callback previously registered with registerAudioPlaybackCallback(android.media.AudioManager.AudioPlaybackCallback, android.os.Handler).

void unregisterAudioRecordingCallback(AudioManager.AudioRecordingCallback cb)

Unregister an audio recording callback previously registered with registerAudioRecordingCallback(android.media.AudioManager.AudioRecordingCallback, android.os.Handler).

void unregisterMediaButtonEventReceiver(PendingIntent eventReceiver)

This method is deprecated. Use MediaSession instead.

void unregisterMediaButtonEventReceiver(ComponentName eventReceiver)

This method is deprecated. Use MediaSession instead.

void unregisterRemoteControlClient(RemoteControlClient rcClient)

This method is deprecated. Use MediaSession instead.

void unregisterRemoteController(RemoteController rctlr)

This method is deprecated. Use MediaSessionManager#removeOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener) instead.

Inherited methods

Constants

ACTION_AUDIO_BECOMING_NOISY

public static final 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. 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"

ACTION_HDMI_AUDIO_PLUG

public static final String ACTION_HDMI_AUDIO_PLUG

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 Context#registerReceiver(BroadcastReceiver, IntentFilter).

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

ACTION_HEADSET_PLUG

public static final String ACTION_HEADSET_PLUG

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"

ACTION_MICROPHONE_MUTE_CHANGED

public static final String ACTION_MICROPHONE_MUTE_CHANGED

Broadcast Action: microphone muting state changed. You cannot receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver().

The intent has no extra values, use isMicrophoneMute() to check whether the microphone is muted.

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

ACTION_SCO_AUDIO_STATE_CHANGED

public static final String ACTION_SCO_AUDIO_STATE_CHANGED

This constant is deprecated.
Use ACTION_SCO_AUDIO_STATE_UPDATED instead

Sticky broadcast intent action indicating that the Bluetooth 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

See also:

Constant Value: "android.media.SCO_AUDIO_STATE_CHANGED"

ACTION_SCO_AUDIO_STATE_UPDATED

public static final String ACTION_SCO_AUDIO_STATE_UPDATED

Sticky broadcast intent action indicating that the Bluetooth 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:

See also:

Constant Value: "android.media.ACTION_SCO_AUDIO_STATE_UPDATED"

ACTION_SPEAKERPHONE_STATE_CHANGED

public static final String ACTION_SPEAKERPHONE_STATE_CHANGED

Broadcast Action: speakerphone state changed. You cannot receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver().

The intent has no extra values, use isSpeakerphoneOn() to check whether the speakerphone functionality is enabled or not.

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

ADJUST_LOWER

public static final int ADJUST_LOWER

Decrease the ringer volume.

See also:

Constant Value: -1 (0xffffffff)

ADJUST_MUTE

public static final int ADJUST_MUTE

Mute the volume. Has no effect if the stream is already muted.

See also:

Constant Value: -100 (0xffffff9c)

ADJUST_RAISE

public static final int ADJUST_RAISE

Increase the ringer volume.

See also:

Constant Value: 1 (0x00000001)

ADJUST_SAME

public static final int ADJUST_SAME

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

See also:

Constant Value: 0 (0x00000000)

ADJUST_TOGGLE_MUTE

public static final int ADJUST_TOGGLE_MUTE

Toggle the mute state. If muted the stream will be unmuted. If not muted the stream will be muted.

See also:

Constant Value: 101 (0x00000065)

ADJUST_UNMUTE

public static final int ADJUST_UNMUTE

Unmute the volume. Has no effect if the stream is not muted.

See also:

Constant Value: 100 (0x00000064)

AUDIOFOCUS_GAIN

public static final int AUDIOFOCUS_GAIN

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

See also:

Constant Value: 1 (0x00000001)

AUDIOFOCUS_GAIN_TRANSIENT

public static final int AUDIOFOCUS_GAIN_TRANSIENT

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.

See also:

Constant Value: 2 (0x00000002)

AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE

public static final 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. 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.

See also:

Constant Value: 4 (0x00000004)

AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK

public static final 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"). Examples of temporary changes are the playback of driving directions where playback of music in the background is acceptable.

See also:

Constant Value: 3 (0x00000003)

AUDIOFOCUS_LOSS

public static final int AUDIOFOCUS_LOSS

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

See also:

Constant Value: -1 (0xffffffff)

AUDIOFOCUS_LOSS_TRANSIENT

public static final int AUDIOFOCUS_LOSS_TRANSIENT

Used to indicate a transient loss of audio focus.

See also:

Constant Value: -2 (0xfffffffe)

AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK

public static final 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.

See also:

Constant Value: -3 (0xfffffffd)

AUDIOFOCUS_NONE

public static final int AUDIOFOCUS_NONE

Used to indicate no audio focus has been gained or lost, or requested.

Constant Value: 0 (0x00000000)

AUDIOFOCUS_REQUEST_DELAYED

public static final int AUDIOFOCUS_REQUEST_DELAYED

A focus change request whose granting is delayed: the request was successful, but the requester will only be granted audio focus once the condition that prevented immediate granting has ended. See requestAudioFocus(android.media.AudioFocusRequest) and AudioFocusRequest.Builder#setAcceptsDelayedFocusGain(boolean)

Constant Value: 2 (0x00000002)

AUDIOFOCUS_REQUEST_FAILED

public static final int AUDIOFOCUS_REQUEST_FAILED

A failed focus change request.

Constant Value: 0 (0x00000000)

AUDIOFOCUS_REQUEST_GRANTED

public static final int AUDIOFOCUS_REQUEST_GRANTED

A successful focus change request.

Constant Value: 1 (0x00000001)

AUDIO_SESSION_ID_GENERATE

public static final 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. This can be used when building a new AudioTrack instance with AudioTrack#AudioTrack(AudioAttributes, AudioFormat, int, int, int).

Constant Value: 0 (0x00000000)

ENCODED_SURROUND_OUTPUT_ALWAYS

public static final int ENCODED_SURROUND_OUTPUT_ALWAYS

The surround sound formats are ALWAYS available, even if they are not detected by the hardware. Those formats will be reported as part of the HDMI output capability. Applications are then free to use either PCM or encoded output.

Constant Value: 2 (0x00000002)

ENCODED_SURROUND_OUTPUT_AUTO

public static final int ENCODED_SURROUND_OUTPUT_AUTO

The surround sound formats are available for use if they are detected. This is the default mode.

Constant Value: 0 (0x00000000)

ENCODED_SURROUND_OUTPUT_MANUAL

public static final int ENCODED_SURROUND_OUTPUT_MANUAL

Surround sound formats are available according to the choice of user, even if they are not detected by the hardware. Those formats will be reported as part of the HDMI output capability. Applications are then free to use either PCM or encoded output.

Constant Value: 3 (0x00000003)

ENCODED_SURROUND_OUTPUT_NEVER

public static final int ENCODED_SURROUND_OUTPUT_NEVER

The surround sound formats are NEVER available, even if they are detected by the hardware. Those formats will not be reported.

Constant Value: 1 (0x00000001)

ENCODED_SURROUND_OUTPUT_UNKNOWN

public static final int ENCODED_SURROUND_OUTPUT_UNKNOWN

The mode for surround sound formats is unknown.

Constant Value: -1 (0xffffffff)

ERROR

public static final int ERROR

A default error code.

Constant Value: -1 (0xffffffff)

ERROR_DEAD_OBJECT

public static final int ERROR_DEAD_OBJECT

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

Constant Value: -6 (0xfffffffa)

EXTRA_AUDIO_PLUG_STATE

public static final String EXTRA_AUDIO_PLUG_STATE

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"

EXTRA_ENCODINGS

public static final String EXTRA_ENCODINGS

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 AudioFormat#ENCODING_PCM_16BIT). Use Intent.getIntArrayExtra(String) to retrieve the encoding values.

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

EXTRA_MAX_CHANNEL_COUNT

public static final String EXTRA_MAX_CHANNEL_COUNT

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"

EXTRA_RINGER_MODE

public static final String EXTRA_RINGER_MODE

The new ringer mode.

See also:

Constant Value: "android.media.EXTRA_RINGER_MODE"

EXTRA_SCO_AUDIO_PREVIOUS_STATE

public static final String EXTRA_SCO_AUDIO_PREVIOUS_STATE

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

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

EXTRA_SCO_AUDIO_STATE

public static final 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.

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

EXTRA_VIBRATE_SETTING

public static final String EXTRA_VIBRATE_SETTING

This constant is deprecated.
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.

See also:

Constant Value: "android.media.EXTRA_VIBRATE_SETTING"

EXTRA_VIBRATE_TYPE

public static final String EXTRA_VIBRATE_TYPE

This constant is deprecated.
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.

See also:

Constant Value: "android.media.EXTRA_VIBRATE_TYPE"

FLAG_ALLOW_RINGER_MODES

public static final int FLAG_ALLOW_RINGER_MODES

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.

See also:

Constant Value: 2 (0x00000002)

FLAG_PLAY_SOUND

public static final int FLAG_PLAY_SOUND

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 AudioManager#STREAM_RING, or the volume is being adjusted downward).

See also:

Constant Value: 4 (0x00000004)

FLAG_REMOVE_SOUND_AND_VIBRATE

public static final int FLAG_REMOVE_SOUND_AND_VIBRATE

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

Constant Value: 8 (0x00000008)

FLAG_SHOW_UI

public static final int FLAG_SHOW_UI

Show a toast containing the current volume.

See also:

Constant Value: 1 (0x00000001)

FLAG_VIBRATE

public static final int FLAG_VIBRATE

Whether to vibrate if going into the vibrate ringer mode.

Constant Value: 16 (0x00000010)

FX_BACK

public static final int FX_BACK

Back sound

See also:

Constant Value: 10 (0x0000000a)

FX_FOCUS_NAVIGATION_DOWN

public static final int FX_FOCUS_NAVIGATION_DOWN

Focus has moved down

See also:

Constant Value: 2 (0x00000002)

FX_FOCUS_NAVIGATION_LEFT

public static final int FX_FOCUS_NAVIGATION_LEFT

Focus has moved left

See also:

Constant Value: 3 (0x00000003)

FX_FOCUS_NAVIGATION_RIGHT

public static final int FX_FOCUS_NAVIGATION_RIGHT

Focus has moved right

See also:

Constant Value: 4 (0x00000004)

FX_FOCUS_NAVIGATION_UP

public static final int FX_FOCUS_NAVIGATION_UP

Focus has moved up

See also:

Constant Value: 1 (0x00000001)

FX_KEYPRESS_DELETE

public static final int FX_KEYPRESS_DELETE

IME delete keypress sound

See also:

Constant Value: 7 (0x00000007)

FX_KEYPRESS_INVALID

public static final int FX_KEYPRESS_INVALID

Invalid keypress sound

See also:

Constant Value: 9 (0x00000009)

FX_KEYPRESS_RETURN

public static final int FX_KEYPRESS_RETURN

IME return_keypress sound

See also:

Constant Value: 8 (0x00000008)

FX_KEYPRESS_SPACEBAR

public static final int FX_KEYPRESS_SPACEBAR

IME spacebar keypress sound

See also:

Constant Value: 6 (0x00000006)

FX_KEYPRESS_STANDARD

public static final int FX_KEYPRESS_STANDARD

IME standard keypress sound

See also:

Constant Value: 5 (0x00000005)

FX_KEY_CLICK

public static final int FX_KEY_CLICK

Keyboard and direction pad click sound

See also:

Constant Value: 0 (0x00000000)

GET_DEVICES_ALL

public static final int GET_DEVICES_ALL

Specifies to the AudioManager#getDevices(int) method to include both source and sink devices.

Constant Value: 3 (0x00000003)

GET_DEVICES_INPUTS

public static final int GET_DEVICES_INPUTS

Specifies to the AudioManager#getDevices(int) method to include source (i.e. input) audio devices.

Constant Value: 1 (0x00000001)

GET_DEVICES_OUTPUTS

public static final int GET_DEVICES_OUTPUTS

Specifies to the AudioManager#getDevices(int) method to include sink (i.e. output) audio devices.

Constant Value: 2 (0x00000002)

MODE_CALL_SCREENING

public static final int MODE_CALL_SCREENING

Call screening in progress. Call is connected and audio is accessible to call screening applications but other audio use cases are still possible.

Constant Value: 4 (0x00000004)

MODE_CURRENT

public static final int MODE_CURRENT

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

Constant Value: -1 (0xffffffff)

MODE_INVALID

public static final int MODE_INVALID

Invalid audio mode.

Constant Value: -2 (0xfffffffe)

MODE_IN_CALL

public static final int MODE_IN_CALL

In call audio mode. A telephony call is established.

Constant Value: 2 (0x00000002)

MODE_IN_COMMUNICATION

public static final int MODE_IN_COMMUNICATION

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

Constant Value: 3 (0x00000003)

MODE_NORMAL

public static final int MODE_NORMAL

Normal audio mode: not ringing and no call established.

Constant Value: 0 (0x00000000)

MODE_RINGTONE

public static final int MODE_RINGTONE

Ringing audio mode. An incoming is being signaled.

Constant Value: 1 (0x00000001)

NUM_STREAMS

public static final int NUM_STREAMS

This constant is deprecated.
Do not iterate on volume stream type values.

Constant Value: 5 (0x00000005)

PLAYBACK_OFFLOAD_GAPLESS_SUPPORTED

public static final int PLAYBACK_OFFLOAD_GAPLESS_SUPPORTED

Return value for getPlaybackOffloadSupport(android.media.AudioFormat, android.media.AudioAttributes): offload playback supported with gapless transitions

Constant Value: 2 (0x00000002)

PLAYBACK_OFFLOAD_NOT_SUPPORTED

public static final int PLAYBACK_OFFLOAD_NOT_SUPPORTED

Return value for getPlaybackOffloadSupport(android.media.AudioFormat, android.media.AudioAttributes): offload playback not supported

Constant Value: 0 (0x00000000)

PLAYBACK_OFFLOAD_SUPPORTED

public static final int PLAYBACK_OFFLOAD_SUPPORTED

Return value for getPlaybackOffloadSupport(android.media.AudioFormat, android.media.AudioAttributes): offload playback supported

Constant Value: 1 (0x00000001)

PROPERTY_OUTPUT_FRAMES_PER_BUFFER

public static final 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 low latency output stream, in decimal PCM frames. Latency-sensitive apps should use this value as a minimum, and offer the user the option to override it. The low latency output stream is typically either the device's primary output stream, or another output stream with smaller buffers.

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

PROPERTY_OUTPUT_SAMPLE_RATE

public static final 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 low latency output stream, in decimal Hz. Latency-sensitive apps should use this value as a default, and offer the user the option to override it. The low latency output stream is typically either the device's primary output stream, or another output stream with smaller buffers.

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

PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED

public static final String PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED

Used as a key for getProperty(String) to determine if the unprocessed audio source is available and supported with the expected frequency range and level response.

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

PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND

public static final String PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND

Used as a key for getProperty(String) to determine if the default microphone audio source supports near-ultrasound frequencies (range of 18 - 21 kHz).

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

PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND

public static final String PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND

Used as a key for getProperty(String) to determine if the default speaker audio path supports near-ultrasound frequencies (range of 18 - 21 kHz).

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

RINGER_MODE_CHANGED_ACTION

public static final String RINGER_MODE_CHANGED_ACTION

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

See also:

Constant Value: "android.media.RINGER_MODE_CHANGED"

RINGER_MODE_NORMAL

public static final int RINGER_MODE_NORMAL

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.

See also:

Constant Value: 2 (0x00000002)

RINGER_MODE_SILENT

public static final int RINGER_MODE_SILENT

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

See also:

Constant Value: 0 (0x00000000)

RINGER_MODE_VIBRATE

public static final int RINGER_MODE_VIBRATE

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

See also:

Constant Value: 1 (0x00000001)

ROUTE_ALL

public static final int ROUTE_ALL

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)

ROUTE_BLUETOOTH

public static final int ROUTE_BLUETOOTH

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

Constant Value: 4 (0x00000004)

ROUTE_BLUETOOTH_A2DP

public static final int ROUTE_BLUETOOTH_A2DP

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)

ROUTE_BLUETOOTH_SCO

public static final int ROUTE_BLUETOOTH_SCO

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)

ROUTE_EARPIECE

public static final int ROUTE_EARPIECE

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

Routing audio output to earpiece

Constant Value: 1 (0x00000001)

ROUTE_HEADSET

public static final int ROUTE_HEADSET

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

Routing audio output to headset

Constant Value: 8 (0x00000008)

ROUTE_SPEAKER

public static final int ROUTE_SPEAKER

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

Routing audio output to speaker

Constant Value: 2 (0x00000002)

SCO_AUDIO_STATE_CONNECTED

public static final 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

Constant Value: 1 (0x00000001)

SCO_AUDIO_STATE_CONNECTING

public static final 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

Constant Value: 2 (0x00000002)

SCO_AUDIO_STATE_DISCONNECTED

public static final 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

Constant Value: 0 (0x00000000)

SCO_AUDIO_STATE_ERROR

public static final int SCO_AUDIO_STATE_ERROR

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

Constant Value: -1 (0xffffffff)

STREAM_ACCESSIBILITY

public static final int STREAM_ACCESSIBILITY

Used to identify the volume of audio streams for accessibility prompts

Constant Value: 10 (0x0000000a)

STREAM_ALARM

public static final int STREAM_ALARM

Used to identify the volume of audio streams for alarms

Constant Value: 4 (0x00000004)

STREAM_DTMF

public static final int STREAM_DTMF

Used to identify the volume of audio streams for DTMF Tones

Constant Value: 8 (0x00000008)

STREAM_MUSIC

public static final int STREAM_MUSIC

Used to identify the volume of audio streams for music playback

Constant Value: 3 (0x00000003)

STREAM_NOTIFICATION

public static final int STREAM_NOTIFICATION

Used to identify the volume of audio streams for notifications

Constant Value: 5 (0x00000005)

STREAM_RING

public static final int STREAM_RING

Used to identify the volume of audio streams for the phone ring

Constant Value: 2 (0x00000002)

STREAM_SYSTEM

public static final int STREAM_SYSTEM

Used to identify the volume of audio streams for system sounds

Constant Value: 1 (0x00000001)

STREAM_VOICE_CALL

public static final int STREAM_VOICE_CALL

Used to identify the volume of audio streams for phone calls

Constant Value: 0 (0x00000000)

USE_DEFAULT_STREAM_TYPE

public static final int USE_DEFAULT_STREAM_TYPE

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

Constant Value: -2147483648 (0x80000000)

VIBRATE_SETTING_CHANGED_ACTION

public static final String VIBRATE_SETTING_CHANGED_ACTION

This constant is deprecated.
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.

See also:

Constant Value: "android.media.VIBRATE_SETTING_CHANGED"

VIBRATE_SETTING_OFF

public static final int VIBRATE_SETTING_OFF

This constant is deprecated.
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.

See also:

Constant Value: 0 (0x00000000)

VIBRATE_SETTING_ON

public static final int VIBRATE_SETTING_ON

This constant is deprecated.
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.

See also:

Constant Value: 1 (0x00000001)

VIBRATE_SETTING_ONLY_SILENT

public static final int VIBRATE_SETTING_ONLY_SILENT

This constant is deprecated.
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.

See also:

Constant Value: 2 (0x00000002)

VIBRATE_TYPE_NOTIFICATION

public static final int VIBRATE_TYPE_NOTIFICATION

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

Vibrate type that corresponds to notifications.

See also:

Constant Value: 1 (0x00000001)

VIBRATE_TYPE_RINGER

public static final int VIBRATE_TYPE_RINGER

This constant is deprecated.
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.

See also:

Constant Value: 0 (0x00000000)

Public methods

abandonAudioFocus

public int abandonAudioFocus (AudioManager.OnAudioFocusChangeListener l)

This method is deprecated.
use abandonAudioFocusRequest(android.media.AudioFocusRequest)

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

Parameters
l AudioManager.OnAudioFocusChangeListener: the listener with which focus was requested.

Returns
int AUDIOFOCUS_REQUEST_FAILED or AUDIOFOCUS_REQUEST_GRANTED

abandonAudioFocusRequest

public int abandonAudioFocusRequest (AudioFocusRequest focusRequest)

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

Parameters
focusRequest AudioFocusRequest: the AudioFocusRequest that was used when requesting focus with requestAudioFocus(android.media.AudioFocusRequest). This value cannot be null.

Returns
int AUDIOFOCUS_REQUEST_FAILED or AUDIOFOCUS_REQUEST_GRANTED

Throws
IllegalArgumentException if passed a null argument

addOnCommunicationDeviceChangedListener

public void addOnCommunicationDeviceChangedListener (Executor executor, 
                AudioManager.OnCommunicationDeviceChangedListener listener)

Adds a listener for being notified of changes to the communication audio device. See setCommunicationDevice(android.media.AudioDeviceInfo).

Parameters
executor Executor: This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). To dispatch events through a shared thread pool, you can use AsyncTask#THREAD_POOL_EXECUTOR.

listener AudioManager.OnCommunicationDeviceChangedListener: This value cannot be null.

addOnModeChangedListener

public void addOnModeChangedListener (Executor executor, 
                AudioManager.OnModeChangedListener listener)

Adds a listener to be notified of changes to the audio mode. See getMode()

Parameters
executor Executor: This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). To dispatch events through a shared thread pool, you can use AsyncTask#THREAD_POOL_EXECUTOR.

listener AudioManager.OnModeChangedListener: This value cannot be null.

adjustStreamVolume

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

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.

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

From N onward, ringer mode adjustments that would toggle Do Not Disturb are not allowed unless the app has been granted Do Not Disturb Access. See NotificationManager#isNotificationPolicyAccessGranted().

Parameters
streamType int: The stream type to adjust. One of STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC, STREAM_ALARM or STREAM_ACCESSIBILITY.

direction int: The direction to adjust the volume. One of ADJUST_LOWER, ADJUST_RAISE, or ADJUST_SAME.

flags int: One or more flags.

Throws
SecurityException if the adjustment triggers a Do Not Disturb change and the caller is not granted notification policy access.

See also:

adjustSuggestedStreamVolume

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

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 int: The direction to adjust the volume. One of ADJUST_LOWER, ADJUST_RAISE, ADJUST_SAME, ADJUST_MUTE, ADJUST_UNMUTE, or ADJUST_TOGGLE_MUTE.

suggestedStreamType int: The stream type that will be used if there isn't a relevant stream. USE_DEFAULT_STREAM_TYPE is valid here.

flags int: One or more flags.

See also:

adjustVolume

public void adjustVolume (int direction, 
                int flags)

Adjusts the volume of the most relevant stream. For example, if a call is active, it will have the highest priority regardless of if the in-call screen is showing. Another example, if music is playing in the background and a call is not active, the music stream will be adjusted.

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 int: The direction to adjust the volume. One of ADJUST_LOWER, ADJUST_RAISE, ADJUST_SAME, ADJUST_MUTE, ADJUST_UNMUTE, or ADJUST_TOGGLE_MUTE.

flags int: One or more flags.

See also:

clearCommunicationDevice

public void clearCommunicationDevice ()

Cancels previous communication device selection made with setCommunicationDevice(android.media.AudioDeviceInfo).

dispatchMediaKeyEvent

public void dispatchMediaKeyEvent (KeyEvent keyEvent)

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

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

Parameters
keyEvent KeyEvent: a KeyEvent instance whose key code is one of KeyEvent#KEYCODE_MUTE, KeyEvent#KEYCODE_HEADSETHOOK, KeyEvent#KEYCODE_MEDIA_PLAY, KeyEvent#KEYCODE_MEDIA_PAUSE, KeyEvent#KEYCODE_MEDIA_PLAY_PAUSE, KeyEvent#KEYCODE_MEDIA_STOP, KeyEvent#KEYCODE_MEDIA_NEXT, KeyEvent#KEYCODE_MEDIA_PREVIOUS, KeyEvent#KEYCODE_MEDIA_REWIND, KeyEvent#KEYCODE_MEDIA_RECORD, KeyEvent#KEYCODE_MEDIA_FAST_FORWARD, KeyEvent#KEYCODE_MEDIA_CLOSE, KeyEvent#KEYCODE_MEDIA_EJECT, or KeyEvent#KEYCODE_MEDIA_AUDIO_TRACK.

generateAudioSessionId

public int generateAudioSessionId ()

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

getActivePlaybackConfigurations

public List<AudioPlaybackConfiguration> getActivePlaybackConfigurations ()

Returns the current active audio playback configurations of the device

Returns
List<AudioPlaybackConfiguration> a non-null list of playback configurations. An empty list indicates there is no playback active when queried.

See also:

getActiveRecordingConfigurations

public List<AudioRecordingConfiguration> getActiveRecordingConfigurations ()

Returns the current active audio recording configurations of the device.

Returns
List<AudioRecordingConfiguration> a non-null list of recording configurations. An empty list indicates there is no recording active when queried.

See also:

getAllowedCapturePolicy

public int getAllowedCapturePolicy ()

Return the capture policy.

Returns
int the capture policy set by setAllowedCapturePolicy(int) or the default if it was not called. Value is AudioAttributes.ALLOW_CAPTURE_BY_ALL, AudioAttributes.ALLOW_CAPTURE_BY_SYSTEM, or AudioAttributes.ALLOW_CAPTURE_BY_NONE

getAudioHwSyncForSession

public int getAudioHwSyncForSession (int sessionId)

Retrieves the Hardware A/V synchronization ID corresponding to the given audio session ID. For more details on Hardware A/V synchronization please refer to media tunneling documentation.

Parameters
sessionId int: the audio session ID for which the HW A/V sync ID is retrieved.

Returns
int the HW A/V sync ID for this audio session (an integer different from 0).

Throws
UnsupportedOperationException if HW A/V synchronization is not supported.

getAvailableCommunicationDevices

public List<AudioDeviceInfo> getAvailableCommunicationDevices ()

Returns a list of audio devices that can be selected for communication use cases via setCommunicationDevice(android.media.AudioDeviceInfo).

Returns
List<AudioDeviceInfo> a list of AudioDeviceInfo suitable for use with setCommunicationDevice(). This value cannot be null.

getCommunicationDevice

public AudioDeviceInfo getCommunicationDevice ()

Returns currently selected audio device for communication.

This API replaces the following deprecated APIs:

Returns
AudioDeviceInfo an AudioDeviceInfo indicating which audio device is currently selected for communication use cases. Can be null on platforms not supporting PackageManager.FEATURE_TELEPHONY. is used.

getDevices

public AudioDeviceInfo[] getDevices (int flags)

Returns an array of AudioDeviceInfo objects corresponding to the audio devices currently connected to the system and meeting the criteria specified in the flags parameter.

Parameters
flags int: A set of bitflags specifying the criteria to test. Value is either 0 or a combination of GET_DEVICES_INPUTS, and GET_DEVICES_OUTPUTS

Returns
AudioDeviceInfo[] A (possibly zero-length) array of AudioDeviceInfo objects.

See also:

getEncodedSurroundMode

public int getEncodedSurroundMode ()

Gets the surround sound mode.

Returns
int true if successful, otherwise false Value is ENCODED_SURROUND_OUTPUT_UNKNOWN, ENCODED_SURROUND_OUTPUT_AUTO, ENCODED_SURROUND_OUTPUT_NEVER, ENCODED_SURROUND_OUTPUT_ALWAYS, or ENCODED_SURROUND_OUTPUT_MANUAL

getMicrophones

public List<MicrophoneInfo> getMicrophones ()

Returns a list of MicrophoneInfo that corresponds to the characteristics of all available microphones. The list is empty when no microphones are available on the device. An error during the query will result in an IOException being thrown.

Returns
List<MicrophoneInfo> a list that contains all microphones' characteristics

Throws
IOException if an error occurs.

getMode

public int getMode ()

Returns the current audio mode.

Returns
int the current audio mode. Value is MODE_NORMAL, MODE_RINGTONE, MODE_IN_CALL, MODE_IN_COMMUNICATION, or MODE_CALL_SCREENING

getParameters

public String getParameters (String keys)

Gets a variable number of parameter values from audio hardware.

Parameters
keys String: list of parameters

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

getPlaybackOffloadSupport

public static int getPlaybackOffloadSupport (AudioFormat format, 
                AudioAttributes attributes)

Returns whether offloaded playback of an audio format is supported on the device or not and when supported whether gapless transitions are possible or not.

Offloaded playback is the feature where the decoding and playback of an audio stream is not competing with other software resources. In general, it is supported by dedicated hardware, such as audio DSPs.

Note that this query only provides information about the support of an audio format, it does not indicate whether the resources necessary for the offloaded playback are available at that instant.

Parameters
format AudioFormat: the audio format (codec, sample rate, channels) being checked. This value cannot be null.

attributes AudioAttributes: the AudioAttributes to be used for playback This value cannot be null.

Returns
int PLAYBACK_OFFLOAD_NOT_SUPPORTED if offload playback if not supported, PLAYBACK_OFFLOAD_SUPPORTED if offload playback is supported or PLAYBACK_OFFLOAD_GAPLESS_SUPPORTED if gapless transitions are also supported. Value is PLAYBACK_OFFLOAD_NOT_SUPPORTED, PLAYBACK_OFFLOAD_SUPPORTED, or PLAYBACK_OFFLOAD_GAPLESS_SUPPORTED

getProperty

public String getProperty (String key)

Returns the value of the property with the specified key.

Parameters
key String: One of the strings corresponding to a property key: either PROPERTY_OUTPUT_SAMPLE_RATE, PROPERTY_OUTPUT_FRAMES_PER_BUFFER, PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND, PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND, or PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED.

Returns
String A string representing the associated value for that property key, or null if there is no value for that key.

getRingerMode

public int getRingerMode ()

Returns the current ringtone mode.

Returns
int The current ringtone mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE.

See also:

getRouting

public int getRouting (int mode)

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 int: audio mode to get route (e.g., MODE_RINGTONE)

Returns
int an audio route bit vector that can be compared with ROUTE_xxx bits

getStreamMaxVolume

public int getStreamMaxVolume (int streamType)

Returns the maximum volume index for a particular stream.

Parameters
streamType int: The stream type whose maximum volume index is returned.

Returns
int The maximum valid volume index for the stream.

See also:

getStreamMinVolume

public int getStreamMinVolume (int streamType)

Returns the minimum volume index for a particular stream.

Parameters
streamType int: The stream type whose minimum volume index is returned. Must be one of STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC, STREAM_ALARM, STREAM_NOTIFICATION, STREAM_DTMF or STREAM_ACCESSIBILITY.

Returns
int The minimum valid volume index for the stream.

See also:

getStreamVolume

public int getStreamVolume (int streamType)

Returns the current volume index for a particular stream.

Parameters
streamType int: The stream type whose volume index is returned.

Returns
int The current volume index for the stream.

See also:

getStreamVolumeDb

public float getStreamVolumeDb (int streamType, 
                int index, 
                int deviceType)

Returns the volume in dB (decibel) for the given stream type at the given volume index, on the given type of audio output device.

Parameters
streamType int: stream type for which the volume is queried. Value is STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC, STREAM_ALARM, STREAM_NOTIFICATION, STREAM_DTMF, or STREAM_ACCESSIBILITY

index int: the volume index for which the volume is queried. The index value must be between the minimum and maximum index values for the given stream type (see getStreamMinVolume(int) and getStreamMaxVolume(int)).

deviceType int: the type of audio output device for which volume is queried. Value is AudioDeviceInfo.TYPE_BUILTIN_EARPIECE, AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, AudioDeviceInfo.TYPE_WIRED_HEADSET, AudioDeviceInfo.TYPE_WIRED_HEADPHONES, AudioDeviceInfo.TYPE_BLUETOOTH_SCO, AudioDeviceInfo.TYPE_BLUETOOTH_A2DP, AudioDeviceInfo.TYPE_HDMI, AudioDeviceInfo.TYPE_DOCK, AudioDeviceInfo.TYPE_USB_ACCESSORY, AudioDeviceInfo.TYPE_USB_DEVICE, AudioDeviceInfo.TYPE_USB_HEADSET, AudioDeviceInfo.TYPE_TELEPHONY, AudioDeviceInfo.TYPE_LINE_ANALOG, AudioDeviceInfo.TYPE_HDMI_ARC, AudioDeviceInfo.TYPE_HDMI_EARC, AudioDeviceInfo.TYPE_LINE_DIGITAL, AudioDeviceInfo.TYPE_FM, AudioDeviceInfo.TYPE_AUX_LINE, AudioDeviceInfo.TYPE_IP, AudioDeviceInfo.TYPE_BUS, AudioDeviceInfo.TYPE_HEARING_AID, AudioDeviceInfo.TYPE_BUILTIN_SPEAKER_SAFE, AudioDeviceInfo.TYPE_BLE_HEADSET, or AudioDeviceInfo.TYPE_BLE_SPEAKER

Returns
float a volume expressed in dB. A negative value indicates the audio signal is attenuated. A typical maximum value at the maximum volume index is 0 dB (no attenuation nor amplification). Muting is reflected by a value of Float#NEGATIVE_INFINITY.

getVibrateSetting

public int getVibrateSetting (int vibrateType)

This method is deprecated.
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 int: The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER.

Returns
int The vibrate setting, one of VIBRATE_SETTING_ON, VIBRATE_SETTING_OFF, or VIBRATE_SETTING_ONLY_SILENT.

See also:

isBluetoothA2dpOn

public boolean isBluetoothA2dpOn ()

This method is deprecated.
Use AudioManager#getDevices(int) instead to list available audio devices.

Checks whether a Bluetooth A2DP audio peripheral is connected or not.

Returns
boolean true if a Bluetooth A2DP peripheral is connected false if otherwise

isBluetoothScoAvailableOffCall

public boolean isBluetoothScoAvailableOffCall ()

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
boolean true if bluetooth SCO can be used for audio when not in call false otherwise

See also:

isBluetoothScoOn

public boolean isBluetoothScoOn ()

Checks whether communications use Bluetooth SCO.

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

isCallScreeningModeSupported

public boolean isCallScreeningModeSupported ()

Indicates if the platform supports a special call screening and call monitoring mode.

When this mode is supported, it is possible to perform call screening and monitoring functions while other use cases like music or movie playback are active.

Use setMode(int) with mode MODE_CALL_SCREENING to place the platform in call screening mode.

If call screening mode is not supported, setting mode to MODE_CALL_SCREENING will be ignored and will not change current mode reported by getMode().

Returns
boolean true if call screening mode is supported, false otherwise.

isHapticPlaybackSupported

public static boolean isHapticPlaybackSupported ()

Return if audio haptic coupled playback is supported or not.

Returns
boolean whether audio haptic playback supported.

isMicrophoneMute

public boolean isMicrophoneMute ()

Checks whether the microphone mute is on or off.

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

isMusicActive

public boolean isMusicActive ()

Checks whether any music is active.

Returns
boolean true if any music tracks are active.

isOffloadedPlaybackSupported

public static boolean isOffloadedPlaybackSupported (AudioFormat format, 
                AudioAttributes attributes)

Returns whether offloaded playback of an audio format is supported on the device.

Offloaded playback is the feature where the decoding and playback of an audio stream is not competing with other software resources. In general, it is supported by dedicated hardware, such as audio DSPs.

Note that this query only provides information about the support of an audio format, it does not indicate whether the resources necessary for the offloaded playback are available at that instant.

Parameters
format AudioFormat: the audio format (codec, sample rate, channels) being checked. This value cannot be null.

attributes AudioAttributes: the AudioAttributes to be used for playback This value cannot be null.

Returns
boolean true if the given audio format can be offloaded.

isSpeakerphoneOn

public boolean isSpeakerphoneOn ()

Checks whether the speakerphone is on or off.

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

isStreamMute

public boolean isStreamMute (int streamType)

Returns the current mute state for a particular stream.

Parameters
streamType int: The stream to get mute state for.

Returns
boolean The mute state for the given stream.

See also:

isSurroundFormatEnabled

public boolean isSurroundFormatEnabled (int audioFormat)

Gets whether a certain surround format is enabled or not.

Parameters
audioFormat int: a surround format Value is AudioFormat.ENCODING_AC3, AudioFormat.ENCODING_E_AC3, AudioFormat.ENCODING_DTS, AudioFormat.ENCODING_DTS_HD, AudioFormat.ENCODING_AAC_LC, AudioFormat.ENCODING_DOLBY_TRUEHD, AudioFormat.ENCODING_AC4, AudioFormat.ENCODING_E_AC3_JOC, AudioFormat.ENCODING_DOLBY_MAT, AudioFormat.ENCODING_MPEGH_BL_L3, AudioFormat.ENCODING_MPEGH_BL_L4, AudioFormat.ENCODING_MPEGH_LC_L3, AudioFormat.ENCODING_MPEGH_LC_L4, AudioFormat.ENCODING_DTS_UHD, or AudioFormat.ENCODING_DRA

Returns
boolean whether the required surround format is enabled

isVolumeFixed

public boolean isVolumeFixed ()

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:

Returns
boolean

isWiredHeadsetOn

public boolean isWiredHeadsetOn ()

This method is deprecated.
Use AudioManager#getDevices(int) instead to list available audio devices.

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
boolean true if a wired headset is connected. false if otherwise

loadSoundEffects

public void loadSoundEffects ()

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

playSoundEffect

public void playSoundEffect (int effectType)

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

Parameters
effectType int: The type of sound effect. NOTE: This version uses the UI settings to determine whether sounds are heard or not. Value is 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, or FX_BACK

playSoundEffect

public void playSoundEffect (int effectType, 
                float volume)

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

Parameters
effectType int: The type of sound effect. Value is 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, or FX_BACK

volume float: 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.

registerAudioDeviceCallback

public void registerAudioDeviceCallback (AudioDeviceCallback callback, 
                Handler handler)

Registers an AudioDeviceCallback object to receive notifications of changes to the set of connected audio devices.

Parameters
callback AudioDeviceCallback: The AudioDeviceCallback object to receive connect/disconnect notifications.

handler Handler: Specifies the Handler object for the thread on which to execute the callback. If null, the Handler associated with the main Looper will be used. This value may be null.

registerAudioPlaybackCallback

public void registerAudioPlaybackCallback (AudioManager.AudioPlaybackCallback cb, 
                Handler handler)

Register a callback to be notified of audio playback changes through AudioPlaybackCallback

Parameters
cb AudioManager.AudioPlaybackCallback: non-null callback to register This value cannot be null.

handler Handler: the Handler object for the thread on which to execute the callback. If null, the Handler associated with the main Looper will be used. This value may be null.

registerAudioRecordingCallback

public void registerAudioRecordingCallback (AudioManager.AudioRecordingCallback cb, 
                Handler handler)

Register a callback to be notified of audio recording changes through AudioRecordingCallback

Parameters
cb AudioManager.AudioRecordingCallback: non-null callback to register This value cannot be null.

handler Handler: the Handler object for the thread on which to execute the callback. If null, the Handler associated with the main Looper will be used. This value may be null.

registerMediaButtonEventReceiver

public void registerMediaButtonEventReceiver (ComponentName eventReceiver)

This method is deprecated.
Use MediaSession#setMediaButtonReceiver(PendingIntent) instead.

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

Parameters
eventReceiver ComponentName: 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.

registerMediaButtonEventReceiver

public void registerMediaButtonEventReceiver (PendingIntent eventReceiver)

This method is deprecated.
Use MediaSession#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 PendingIntent: target that will receive media button intents. The PendingIntent will be sent an Intent#ACTION_MEDIA_BUTTON event when a media button action occurs, with Intent#EXTRA_KEY_EVENT added and holding the key code of the media button that was pressed.

registerRemoteControlClient

public void registerRemoteControlClient (RemoteControlClient rcClient)

This method is deprecated.
Use MediaSession instead.

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

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

See also:

registerRemoteController

public boolean registerRemoteController (RemoteController rctlr)

This method is deprecated.
Use MediaSessionManager#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 RemoteController: the object to register.

Returns
boolean true if the RemoteController was successfully registered, false if an error occurred, due to an internal system error, or insufficient permissions.

removeOnCommunicationDeviceChangedListener

public void removeOnCommunicationDeviceChangedListener (AudioManager.OnCommunicationDeviceChangedListener listener)

Removes a previously added listener of changes to the communication audio device. See setCommunicationDevice(android.media.AudioDeviceInfo).

Parameters
listener AudioManager.OnCommunicationDeviceChangedListener: This value cannot be null.

removeOnModeChangedListener

public void removeOnModeChangedListener (AudioManager.OnModeChangedListener listener)

Removes a previously added listener for changes to audio mode. See getMode()

Parameters
listener AudioManager.OnModeChangedListener: This value cannot be null.

requestAudioFocus

public int requestAudioFocus (AudioFocusRequest focusRequest)

Request audio focus. See the AudioFocusRequest for information about the options available to configure your request, and notification of focus gain and loss.

Parameters
focusRequest AudioFocusRequest: a AudioFocusRequest instance used to configure how focus is requested. This value cannot be null.

Returns
int AUDIOFOCUS_REQUEST_FAILED, AUDIOFOCUS_REQUEST_GRANTED or AUDIOFOCUS_REQUEST_DELAYED.
Note that the return value is never AUDIOFOCUS_REQUEST_DELAYED when focus is requested without building the AudioFocusRequest with AudioFocusRequest.Builder#setAcceptsDelayedFocusGain(boolean) set to true.

Throws
NullPointerException if passed a null argument

requestAudioFocus

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

This method is deprecated.
use requestAudioFocus(android.media.AudioFocusRequest)

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

Parameters
l AudioManager.OnAudioFocusChangeListener: the listener to be notified of audio focus changes

streamType int: the main audio stream type affected by the focus request

durationHint int: 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.

Returns
int AUDIOFOCUS_REQUEST_FAILED or AUDIOFOCUS_REQUEST_GRANTED

setAllowedCapturePolicy

public void setAllowedCapturePolicy (int capturePolicy)

Specifies whether the audio played by this app may or may not be captured by other apps or the system. The default is AudioAttributes#ALLOW_CAPTURE_BY_ALL. There are multiple ways to set this policy:

The most restrictive policy is always applied. See AudioPlaybackCaptureConfiguration for more details on which audio signals can be captured.

Parameters
capturePolicy int: one of AudioAttributes#ALLOW_CAPTURE_BY_ALL, AudioAttributes#ALLOW_CAPTURE_BY_SYSTEM, AudioAttributes#ALLOW_CAPTURE_BY_NONE. Value is AudioAttributes.ALLOW_CAPTURE_BY_ALL, AudioAttributes.ALLOW_CAPTURE_BY_SYSTEM, or AudioAttributes.ALLOW_CAPTURE_BY_NONE

Throws
RuntimeException if the argument is not a valid value.

setBluetoothA2dpOn

public void setBluetoothA2dpOn (boolean on)

This method is deprecated.
Do not use.

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

setBluetoothScoOn

public void setBluetoothScoOn (boolean on)

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 boolean: set true to use bluetooth SCO for communications; false to not use bluetooth SCO for communications

setCommunicationDevice

public boolean setCommunicationDevice (AudioDeviceInfo device)

Selects the audio device that should be used for communication use cases, for instance voice or video calls. This method can be used by voice or video chat applications to select a different audio device than the one selected by default by the platform.

The device selection is expressed as an AudioDeviceInfo among devices returned by getAvailableCommunicationDevices(). The selection is active as long as the requesting application process lives, until clearCommunicationDevice() is called or until the device is disconnected. It is therefore important for applications to clear the request when a call ends or the the requesting activity or service is stopped or destroyed.

In case of simultaneous requests by multiple applications the priority is given to the application currently controlling the audio mode (see setMode(int)). This is the latest application having selected mode MODE_IN_COMMUNICATION or mode MODE_IN_CALL. Note that MODE_IN_CALL can only be selected by the main telephony application with permission Manifest.permission.MODIFY_PHONE_STATE.

If the requested devices is not currently available, the request will be rejected and the method will return false.

This API replaces the following deprecated APIs:

Example

The example below shows how to enable and disable speakerphone mode.

 // Get an AudioManager instance
 AudioManager audioManager = Context.getSystemService(AudioManager.class);
 AudioDeviceInfo speakerDevice = null;
 List devices = audioManager.getAvailableCommunicationDevices();
 for (AudioDeviceInfo device : devices) {
     if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
         speakerDevice = device;
         break;
     }
 }
 if (speakerDevice != null) {
     // Turn speakerphone ON.
     boolean result = audioManager.setCommunicationDevice(speakerDevice);
     if (!result) {
         // Handle error.
     }
     // Turn speakerphone OFF.
     audioManager.clearCommunicationDevice();
 }
 

Parameters
device AudioDeviceInfo: the requested audio device. This value cannot be null.

Returns
boolean true if the request was accepted, false otherwise.

Throws
IllegalArgumentException If an invalid device is specified.

setEncodedSurroundMode

public boolean setEncodedSurroundMode (int mode)

Sets the surround sound mode.
Requires Manifest.permission.WRITE_SETTINGS

Parameters
mode int: Value is ENCODED_SURROUND_OUTPUT_UNKNOWN, ENCODED_SURROUND_OUTPUT_AUTO, ENCODED_SURROUND_OUTPUT_NEVER, ENCODED_SURROUND_OUTPUT_ALWAYS, or ENCODED_SURROUND_OUTPUT_MANUAL

Returns
boolean true if successful, otherwise false

setMicrophoneMute

public void setMicrophoneMute (boolean on)

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 boolean: set true to mute the microphone; false to turn mute off

setMode

public void setMode (int mode)

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 int: the requested audio mode. Informs the HAL about the current audio state so that it can route the audio appropriately. Value is MODE_NORMAL, MODE_RINGTONE, MODE_IN_CALL, MODE_IN_COMMUNICATION, or MODE_CALL_SCREENING

setParameters

public void setParameters (String keyValuePairs)

Sets a variable number of parameter values to audio hardware.

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

setRingerMode

public void setRingerMode (int ringerMode)

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

From N onward, ringer mode adjustments that would toggle Do Not Disturb are not allowed unless the app has been granted Do Not Disturb Access. See NotificationManager#isNotificationPolicyAccessGranted().

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

See also:

setRouting

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

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 int: audio mode to change route. E.g., MODE_RINGTONE.

routes int: bit vector of routes requested, created from one or more of ROUTE_xxx types. Set bits indicate that route should be on

mask int: bit vector of routes to change, created from one or more of ROUTE_xxx types. Unset bits indicate the route should be left unchanged

setSpeakerphoneOn

public void setSpeakerphoneOn (boolean on)

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 boolean: set true to turn on speakerphone; false to turn it off

setStreamMute

public void setStreamMute (int streamType, 
                boolean state)

This method is deprecated.
Use adjustStreamVolume(int, int, int) with ADJUST_MUTE or ADJUST_UNMUTE instead.

Mute or unmute an audio 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().

This method was deprecated in API level 22. Prior to API level 22 this method had significantly different behavior and should be used carefully. The following applies only to pre-22 platforms:

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

Parameters
streamType int: The stream to be muted/unmuted.

state boolean: The required mute state: true for mute ON, false for mute OFF

See also:

setStreamSolo

public void setStreamSolo (int streamType, 
                boolean state)

This method is deprecated.
Do not use. If you need exclusive audio playback use requestAudioFocus(AudioFocusRequest).

Solo or unsolo a particular stream.

Do not use. This method has been deprecated and is now a no-op. requestAudioFocus(AudioFocusRequest) should be used for exclusive audio playback.

Parameters
streamType int: The stream to be soloed/unsoloed.

state boolean: The required solo state: true for solo ON, false for solo OFF

See also:

setStreamVolume

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

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

From N onward, volume adjustments that would toggle Do Not Disturb are not allowed unless the app has been granted Do Not Disturb Access. See NotificationManager#isNotificationPolicyAccessGranted().

Parameters
streamType int: The stream whose volume index should be set.

index int: The volume index to set. See getStreamMaxVolume(int) for the largest valid value.

flags int: One or more flags.

Throws
SecurityException if the volume change triggers a Do Not Disturb change and the caller is not granted notification policy access.

See also:

setSurroundFormatEnabled

public boolean setSurroundFormatEnabled (int audioFormat, 
                boolean enabled)

Sets and persists a certain surround format as enabled or not.

This API is called by TvSettings surround sound menu when user enables or disables a surround sound format. This setting is persisted as global user setting. Applications should revert their changes to surround sound settings unless they intend to modify the global user settings across all apps. The framework does not auto-revert an application's settings after a lifecycle event. Audio focus is not required to apply these settings.
Requires Manifest.permission.WRITE_SETTINGS

Parameters
audioFormat int: Value is AudioFormat.ENCODING_AC3, AudioFormat.ENCODING_E_AC3, AudioFormat.ENCODING_DTS, AudioFormat.ENCODING_DTS_HD, AudioFormat.ENCODING_AAC_LC, AudioFormat.ENCODING_DOLBY_TRUEHD, AudioFormat.ENCODING_AC4, AudioFormat.ENCODING_E_AC3_JOC, AudioFormat.ENCODING_DOLBY_MAT, AudioFormat.ENCODING_MPEGH_BL_L3, AudioFormat.ENCODING_MPEGH_BL_L4, AudioFormat.ENCODING_MPEGH_LC_L3, AudioFormat.ENCODING_MPEGH_LC_L4, AudioFormat.ENCODING_DTS_UHD, or AudioFormat.ENCODING_DRA

enabled boolean: the required surround format state, true for enabled, false for disabled

Returns
boolean true if successful, otherwise false

setVibrateSetting

public void setVibrateSetting (int vibrateType, 
                int vibrateSetting)

This method is deprecated.
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 int: The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER.

vibrateSetting int: The vibrate setting, one of VIBRATE_SETTING_ON, VIBRATE_SETTING_OFF, or VIBRATE_SETTING_ONLY_SILENT.

See also:

setWiredHeadsetOn

public void setWiredHeadsetOn (boolean on)

This method is deprecated.
Do not use.

Sets audio routing to the wired headset on or off.

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

shouldVibrate

public boolean shouldVibrate (int vibrateType)

This method is deprecated.
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 int: The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER.

Returns
boolean Whether the type should vibrate at the instant this method is called.

See also:

startBluetoothSco

public void startBluetoothSco ()

Start bluetooth SCO audio connection.

Requires Permission: Manifest.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 Build.VERSION_CODES.JELLY_BEAN_MR1, this method initiates a virtual voice call to the bluetooth headset. After API version Build.VERSION_CODES.JELLY_BEAN_MR2 only a raw SCO audio connection is established.

See also:

stopBluetoothSco

public void stopBluetoothSco ()

Stop bluetooth SCO audio connection.

Requires Permission: Manifest.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.

See also:

unloadSoundEffects

public void unloadSoundEffects ()

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

unregisterAudioDeviceCallback

public void unregisterAudioDeviceCallback (AudioDeviceCallback callback)

Unregisters an AudioDeviceCallback object which has been previously registered to receive notifications of changes to the set of connected audio devices.

Parameters
callback AudioDeviceCallback: The AudioDeviceCallback object that was previously registered with AudioManager#registerAudioDeviceCallback to be unregistered.

unregisterAudioPlaybackCallback

public void unregisterAudioPlaybackCallback (AudioManager.AudioPlaybackCallback cb)

Unregister an audio playback callback previously registered with registerAudioPlaybackCallback(android.media.AudioManager.AudioPlaybackCallback, android.os.Handler).

Parameters
cb AudioManager.AudioPlaybackCallback: non-null callback to unregister This value cannot be null.

unregisterAudioRecordingCallback

public void unregisterAudioRecordingCallback (AudioManager.AudioRecordingCallback cb)

Unregister an audio recording callback previously registered with registerAudioRecordingCallback(android.media.AudioManager.AudioRecordingCallback, android.os.Handler).

Parameters
cb AudioManager.AudioRecordingCallback: non-null callback to unregister This value cannot be null.

unregisterMediaButtonEventReceiver

public void unregisterMediaButtonEventReceiver (PendingIntent eventReceiver)

This method is deprecated.
Use MediaSession instead.

Unregister the receiver of MEDIA_BUTTON intents.

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

unregisterMediaButtonEventReceiver

public void unregisterMediaButtonEventReceiver (ComponentName eventReceiver)

This method is deprecated.
Use MediaSession instead.

Unregister the receiver of MEDIA_BUTTON intents.

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

unregisterRemoteControlClient

public void unregisterRemoteControlClient (RemoteControlClient rcClient)

This method is deprecated.
Use MediaSession instead.

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

Parameters
rcClient RemoteControlClient: The remote control client to unregister.

See also:

unregisterRemoteController

public void unregisterRemoteController (RemoteController rctlr)

This method is deprecated.
Use MediaSessionManager#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 RemoteController: the object to unregister.