public class AudioManager extends Object
Use Context.getSystemService(Context.AUDIO_SERVICE)
to get
an instance of this class.
Modifier and Type | Class and Description |
---|---|
static class |
AudioManager.AudioRecordingCallback
Interface for receiving update notifications about the recording configuration.
|
static interface |
AudioManager.OnAudioFocusChangeListener
Interface definition for a callback to be invoked when the audio focus of the system is
updated.
|
static interface |
AudioManager.OnAudioPortUpdateListener
Listener registered by client to be notified upon new audio port connections,
disconnections or attributes update.
|
Modifier and Type | Field and Description |
---|---|
static 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.
|
static String |
ACTION_HDMI_AUDIO_PLUG
Broadcast Action: A sticky broadcast indicating an HDMI cable was plugged or unplugged.
|
static String |
ACTION_HEADSET_PLUG
Broadcast Action: Wired Headset plugged in or unplugged.
|
static String |
ACTION_SCO_AUDIO_STATE_CHANGED
Deprecated.
Use
ACTION_SCO_AUDIO_STATE_UPDATED instead |
static String |
ACTION_SCO_AUDIO_STATE_UPDATED
Sticky broadcast intent action indicating that the bluetoooth SCO audio
connection state has been updated.
|
static int |
ADJUST_LOWER
Decrease the ringer volume.
|
static int |
ADJUST_MUTE
Mute the volume.
|
static int |
ADJUST_RAISE
Increase the ringer volume.
|
static int |
ADJUST_SAME
Maintain the previous ringer volume.
|
static int |
ADJUST_TOGGLE_MUTE
Toggle the mute state.
|
static int |
ADJUST_UNMUTE
Unmute the volume.
|
static 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.
|
static int |
AUDIOFOCUS_FLAG_DELAY_OK |
static int |
AUDIOFOCUS_FLAG_LOCK |
static int |
AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS |
static int |
AUDIOFOCUS_FLAGS_APPS |
static int |
AUDIOFOCUS_FLAGS_SYSTEM |
static int |
AUDIOFOCUS_GAIN
Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration.
|
static int |
AUDIOFOCUS_GAIN_TRANSIENT
Used to indicate a temporary gain or request of audio focus, anticipated to last a short
amount of time.
|
static 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.
|
static 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").
|
static int |
AUDIOFOCUS_LOSS
Used to indicate a loss of audio focus of unknown duration.
|
static int |
AUDIOFOCUS_LOSS_TRANSIENT
Used to indicate a transient loss of audio focus.
|
static 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.
|
static int |
AUDIOFOCUS_NONE |
static int |
AUDIOFOCUS_REQUEST_DELAYED |
static int |
AUDIOFOCUS_REQUEST_FAILED
A failed focus change request.
|
static int |
AUDIOFOCUS_REQUEST_GRANTED
A successful focus change request.
|
static int |
DEVICE_IN_ANLG_DOCK_HEADSET |
static int |
DEVICE_IN_BACK_MIC |
static int |
DEVICE_IN_BLUETOOTH_SCO_HEADSET |
static int |
DEVICE_IN_BUILTIN_MIC |
static int |
DEVICE_IN_DGTL_DOCK_HEADSET |
static int |
DEVICE_IN_FM_TUNER |
static int |
DEVICE_IN_HDMI |
static int |
DEVICE_IN_LINE |
static int |
DEVICE_IN_LOOPBACK |
static int |
DEVICE_IN_SPDIF |
static int |
DEVICE_IN_TELEPHONY_RX |
static int |
DEVICE_IN_TV_TUNER |
static int |
DEVICE_IN_USB_ACCESSORY |
static int |
DEVICE_IN_USB_DEVICE |
static int |
DEVICE_IN_WIRED_HEADSET |
static int |
DEVICE_NONE |
static int |
DEVICE_OUT_ANLG_DOCK_HEADSET |
static int |
DEVICE_OUT_AUX_DIGITAL |
static int |
DEVICE_OUT_BLUETOOTH_A2DP |
static int |
DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
static int |
DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
static int |
DEVICE_OUT_BLUETOOTH_SCO |
static int |
DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
static int |
DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
static int |
DEVICE_OUT_DEFAULT |
static int |
DEVICE_OUT_DGTL_DOCK_HEADSET |
static int |
DEVICE_OUT_EARPIECE |
static int |
DEVICE_OUT_FM |
static int |
DEVICE_OUT_HDMI |
static int |
DEVICE_OUT_HDMI_ARC |
static int |
DEVICE_OUT_LINE |
static int |
DEVICE_OUT_REMOTE_SUBMIX |
static int |
DEVICE_OUT_SPDIF |
static int |
DEVICE_OUT_SPEAKER |
static int |
DEVICE_OUT_TELEPHONY_TX |
static int |
DEVICE_OUT_USB_ACCESSORY |
static int |
DEVICE_OUT_USB_DEVICE |
static int |
DEVICE_OUT_WIRED_HEADPHONE |
static int |
DEVICE_OUT_WIRED_HEADSET |
static int |
ERROR
A default error code.
|
static int |
ERROR_BAD_VALUE |
static int |
ERROR_DEAD_OBJECT
An error code indicating that the object reporting it is no longer valid and needs to
be recreated.
|
static int |
ERROR_INVALID_OPERATION |
static int |
ERROR_NO_INIT |
static int |
ERROR_PERMISSION_DENIED |
static String |
EXTRA_AUDIO_PLUG_STATE
Extra used in
ACTION_HDMI_AUDIO_PLUG to communicate whether HDMI is plugged in
or unplugged. |
static String |
EXTRA_ENCODINGS
Extra used in
ACTION_HDMI_AUDIO_PLUG to define the audio encodings supported by
the connected HDMI device. |
static String |
EXTRA_MASTER_VOLUME_MUTED |
static String |
EXTRA_MAX_CHANNEL_COUNT
Extra used in
ACTION_HDMI_AUDIO_PLUG to define the maximum number of channels
supported by the HDMI device. |
static String |
EXTRA_PREV_VOLUME_STREAM_DEVICES |
static String |
EXTRA_PREV_VOLUME_STREAM_VALUE |
static String |
EXTRA_RINGER_MODE
The new ringer mode.
|
static String |
EXTRA_SCO_AUDIO_PREVIOUS_STATE
Extra for intent
ACTION_SCO_AUDIO_STATE_UPDATED containing the previous
bluetooth SCO connection state. |
static 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. |
static String |
EXTRA_STREAM_VOLUME_MUTED |
static String |
EXTRA_VIBRATE_SETTING
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode and listen to
RINGER_MODE_CHANGED_ACTION instead. |
static String |
EXTRA_VIBRATE_TYPE
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode and listen to
RINGER_MODE_CHANGED_ACTION instead. |
static String |
EXTRA_VOLUME_STREAM_DEVICES |
static String |
EXTRA_VOLUME_STREAM_TYPE |
static String |
EXTRA_VOLUME_STREAM_TYPE_ALIAS |
static String |
EXTRA_VOLUME_STREAM_VALUE |
static int |
FLAG_ACTIVE_MEDIA_ONLY
Indicates that this should only be handled if media is actively playing.
|
static int |
FLAG_ALLOW_RINGER_MODES
Whether to include ringer modes as possible options when changing volume.
|
static int |
FLAG_BLUETOOTH_ABS_VOLUME
Indicates the volume set/adjust call is for Bluetooth absolute volume
|
static int |
FLAG_FIXED_VOLUME
Indicates to VolumePanel that the volume slider should be disabled as user
cannot change the stream volume
|
static int |
FLAG_FROM_KEY
Adjusting the volume due to a hardware key press.
|
static int |
FLAG_HDMI_SYSTEM_AUDIO_VOLUME
Indicates the volume call is for Hdmi Cec system audio volume
|
static int |
FLAG_PLAY_SOUND
Whether to play a sound when changing the volume.
|
static int |
FLAG_REMOVE_SOUND_AND_VIBRATE
Removes any sounds/vibrate that may be in the queue, or are playing (related to
changing volume).
|
static int |
FLAG_SHOW_SILENT_HINT
Adjusting the volume was prevented due to silent mode, display a hint in the UI.
|
static int |
FLAG_SHOW_UI
Show a toast containing the current volume.
|
static int |
FLAG_SHOW_UI_WARNINGS
Like FLAG_SHOW_UI, but only dialog warnings and confirmations, no sliders.
|
static int |
FLAG_SHOW_VIBRATE_HINT
Adjusting the volume down from vibrated was prevented, display a hint in the UI.
|
static int |
FLAG_VIBRATE
Whether to vibrate if going into the vibrate ringer mode.
|
static int |
FX_FOCUS_NAVIGATION_DOWN
Focus has moved down
|
static int |
FX_FOCUS_NAVIGATION_LEFT
Focus has moved left
|
static int |
FX_FOCUS_NAVIGATION_RIGHT
Focus has moved right
|
static int |
FX_FOCUS_NAVIGATION_UP
Focus has moved up
|
static int |
FX_KEY_CLICK
Keyboard and direction pad click sound
|
static int |
FX_KEYPRESS_DELETE
IME delete keypress sound
|
static int |
FX_KEYPRESS_INVALID
Invalid keypress sound
|
static int |
FX_KEYPRESS_RETURN
IME return_keypress sound
|
static int |
FX_KEYPRESS_SPACEBAR
IME spacebar keypress sound
|
static int |
FX_KEYPRESS_STANDARD
IME standard keypress sound
|
static int |
GET_DEVICES_ALL
Specifies to the
getDevices(int) method to include both
source and sink devices. |
static int |
GET_DEVICES_INPUTS
Specifies to the
getDevices(int) method to include
source (i.e. input) audio devices. |
static int |
GET_DEVICES_OUTPUTS
Specifies to the
getDevices(int) method to include
sink (i.e. output) audio devices. |
static String |
INTERNAL_RINGER_MODE_CHANGED_ACTION |
static String |
MASTER_MUTE_CHANGED_ACTION |
static int |
MODE_CURRENT
Current audio mode.
|
static int |
MODE_IN_CALL
In call audio mode.
|
static int |
MODE_IN_COMMUNICATION
In communication audio mode.
|
static int |
MODE_INVALID
Invalid audio mode.
|
static int |
MODE_NORMAL
Normal audio mode: not ringing and no call established.
|
static int |
MODE_RINGTONE
Ringing audio mode.
|
static int |
NUM_SOUND_EFFECTS |
static int |
NUM_STREAMS
Deprecated.
Use AudioSystem.getNumStreamTypes() instead
|
static String |
PROPERTY_OUTPUT_FRAMES_PER_BUFFER
Used as a key for
getProperty(java.lang.String) to request the native or optimal output buffer size
for this device's low latency output stream, in decimal PCM frames. |
static String |
PROPERTY_OUTPUT_SAMPLE_RATE
Used as a key for
getProperty(java.lang.String) to request the native or optimal output sample rate
for this device's low latency output stream, in decimal Hz. |
static String |
PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED
Used as a key for
getProperty(java.lang.String) to determine if the unprocessed audio source is
available and supported with the expected frequency range and level response. |
static String |
PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND
Used as a key for
getProperty(java.lang.String) to determine if the default microphone audio source
supports near-ultrasound frequencies (range of 18 - 21 kHz). |
static String |
PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND
Used as a key for
getProperty(java.lang.String) to determine if the default speaker audio path
supports near-ultrasound frequencies (range of 18 - 21 kHz). |
static int |
RECORD_CONFIG_EVENT_START |
static int |
RECORD_CONFIG_EVENT_STOP |
static String |
RINGER_MODE_CHANGED_ACTION
Sticky broadcast intent action indicating that the ringer mode has
changed.
|
static int |
RINGER_MODE_MAX
Maximum valid ringer mode value.
|
static int |
RINGER_MODE_NORMAL
Ringer mode that may be audible and may vibrate.
|
static int |
RINGER_MODE_SILENT
Ringer mode that will be silent and will not vibrate.
|
static int |
RINGER_MODE_VIBRATE
Ringer mode that will be silent and will vibrate.
|
static int |
ROUTE_ALL
Deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(),
setBluetoothScoOn() methods instead.
|
static int |
ROUTE_BLUETOOTH
Deprecated.
|
static int |
ROUTE_BLUETOOTH_A2DP
Deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(),
setBluetoothScoOn() methods instead.
|
static int |
ROUTE_BLUETOOTH_SCO
Deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(),
setBluetoothScoOn() methods instead.
|
static int |
ROUTE_EARPIECE
Deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(),
setBluetoothScoOn() methods instead.
|
static int |
ROUTE_HEADSET
Deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(),
setBluetoothScoOn() methods instead.
|
static int |
ROUTE_SPEAKER
Deprecated.
Do not set audio routing directly, use setSpeakerphoneOn(),
setBluetoothScoOn() methods instead.
|
static 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 |
static 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
|
static 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
|
static int |
SCO_AUDIO_STATE_ERROR
Value for extra EXTRA_SCO_AUDIO_STATE indicating that
there was an error trying to obtain the state
|
static int |
STREAM_ALARM
The audio stream for alarms
|
static int |
STREAM_BLUETOOTH_SCO |
static String |
STREAM_DEVICES_CHANGED_ACTION |
static int |
STREAM_DTMF
The audio stream for DTMF Tones
|
static int |
STREAM_MUSIC
The audio stream for music playback
|
static String |
STREAM_MUTE_CHANGED_ACTION |
static int |
STREAM_NOTIFICATION
The audio stream for notifications
|
static int |
STREAM_RING
The audio stream for the phone ring
|
static int |
STREAM_SYSTEM
The audio stream for system sounds
|
static int |
STREAM_SYSTEM_ENFORCED |
static int |
STREAM_TTS |
static int |
STREAM_VOICE_CALL
The audio stream for phone calls
|
static int |
SUCCESS |
static int |
USE_DEFAULT_STREAM_TYPE
Suggests using the default stream type.
|
static String |
VIBRATE_SETTING_CHANGED_ACTION
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode and listen to
RINGER_MODE_CHANGED_ACTION instead. |
static int |
VIBRATE_SETTING_OFF
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode that can be queried via
getRingerMode() . |
static int |
VIBRATE_SETTING_ON
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode that can be queried via
getRingerMode() . |
static int |
VIBRATE_SETTING_ONLY_SILENT
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode that can be queried via
getRingerMode() . |
static int |
VIBRATE_TYPE_NOTIFICATION
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode that can be queried via
getRingerMode() . |
static int |
VIBRATE_TYPE_RINGER
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode that can be queried via
getRingerMode() . |
static String |
VOLUME_CHANGED_ACTION |
Constructor and Description |
---|
AudioManager(Context context) |
Modifier and Type | Method and Description |
---|---|
int |
abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l)
Abandon audio focus.
|
int |
abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l,
AudioAttributes aa) |
void |
abandonAudioFocusForCall() |
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 |
avrcpSupportsAbsoluteVolume(String address,
boolean support) |
static int |
createAudioPatch(AudioPatch[] patch,
AudioPortConfig[] sources,
AudioPortConfig[] sinks)
Create a connection between two or more devices.
|
void |
disableSafeMediaVolume()
Only useful for volume controllers.
|
void |
dispatchMediaKeyEvent(KeyEvent keyEvent)
Sends a simulated key event for a media button.
|
static String |
flagsToString(int flags) |
void |
forceVolumeControlStream(int streamType)
forces the stream controlled by hard volume keys
specifying streamType == -1 releases control to the
logic.
|
int |
generateAudioSessionId()
Return a new audio session identifier not associated with any player or effect.
|
List<AudioRecordingConfiguration> |
getActiveRecordingConfigurations()
Returns the current active audio recording configurations of the device.
|
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 |
getDevicesForStream(int streamType)
Return the enabled devices for the specified output stream type.
|
static AudioDeviceInfo[] |
getDevicesStatic(int flags)
Generates a list of AudioDeviceInfo objects corresponding to the audio devices currently
connected to the system and meeting the criteria specified in the
flags
parameter. |
int |
getLastAudibleStreamVolume(int streamType)
Get last audible volume before stream was muted.
|
int |
getMode()
Returns the current audio mode.
|
int |
getOutputLatency(int streamType)
Returns the estimated latency for the given stream type in milliseconds.
|
String |
getParameters(String keys)
Gets a variable number of parameter values from audio hardware.
|
String |
getProperty(String key)
Returns the value of the property with the specified key.
|
int |
getRingerMode()
Returns the current ringtone mode.
|
int |
getRingerModeInternal()
Only useful for volume controllers.
|
IRingtonePlayer |
getRingtonePlayer() |
int |
getRouting(int mode)
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.
|
int |
getUiSoundsStreamType()
Get the stream type whose volume is driving the UI sounds volume.
|
int |
getVibrateSetting(int vibrateType)
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode that can be queried via
getRingerMode() . |
void |
handleKeyDown(KeyEvent event,
int stream) |
void |
handleKeyUp(KeyEvent event,
int stream) |
boolean |
isAudioFocusExclusive() |
boolean |
isBluetoothA2dpOn()
Checks whether A2DP audio routing to the Bluetooth headset is on or off.
|
boolean |
isBluetoothScoAvailableOffCall()
Indicates if current platform supports use of SCO for off call use cases.
|
boolean |
isBluetoothScoOn()
Checks whether communications use Bluetooth SCO.
|
boolean |
isHdmiSystemAudioSupported()
Returns true if Hdmi Cec system audio mode is supported.
|
static boolean |
isInputDevice(int device)
Return true if the device code corresponds to an input device.
|
boolean |
isMasterMute()
get master mute state.
|
boolean |
isMicrophoneMute()
Checks whether the microphone mute is on or off.
|
boolean |
isMusicActive()
Checks whether any music is active.
|
boolean |
isMusicActiveRemotely() |
static boolean |
isOutputDevice(int device)
Return true if the device code corresponds to an output device.
|
boolean |
isSilentMode()
Checks whether the phone is in silent mode, with or without vibrate.
|
boolean |
isSpeakerphoneOn()
Checks whether the speakerphone is on or off.
|
boolean |
isStreamAffectedByMute(int streamType)
Only useful for volume controllers.
|
boolean |
isStreamAffectedByRingerMode(int streamType)
Only useful for volume controllers.
|
boolean |
isStreamMute(int streamType)
Returns the current mute state for a particular stream.
|
static boolean |
isValidRingerMode(int ringerMode)
Checks valid ringer mode values.
|
boolean |
isVolumeFixed()
Indicates if the device implements a fixed volume policy.
|
boolean |
isWiredHeadsetOn()
Deprecated.
Use only to check is a headset is connected or not.
|
static int |
listAudioDevicePorts(ArrayList<AudioDevicePort> devices)
Specialized version of listAudioPorts() listing only audio devices (AudioDevicePort)
|
static int |
listAudioPatches(ArrayList<AudioPatch> patches)
List all existing connections between audio ports.
|
static int |
listAudioPorts(ArrayList<AudioPort> ports)
Returns a list of descriptors for all audio ports managed by the audio framework.
|
static int |
listPreviousAudioDevicePorts(ArrayList<AudioDevicePort> devices)
Specialized version of listPreviousAudioPorts() listing only audio devices (AudioDevicePort)
|
static int |
listPreviousAudioPorts(ArrayList<AudioPort> ports)
Returns a list of descriptors for all audio ports managed by the audio framework as
it was before the last update calback.
|
void |
loadSoundEffects()
Load Sound effects.
|
void |
notifyVolumeControllerVisible(IVolumeController controller,
boolean visible)
Notify audio manager about volume controller visibility changes.
|
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 |
playSoundEffect(int effectType,
int userId)
Plays a sound effect (Key clicks, lid open/close...)
|
void |
preDispatchKeyEvent(KeyEvent event,
int stream) |
void |
registerAudioDeviceCallback(AudioDeviceCallback callback,
Handler handler)
Registers an
AudioDeviceCallback object to receive notifications of changes
to the set of connected audio devices. |
void |
registerAudioFocusListener(AudioManager.OnAudioFocusChangeListener l) |
int |
registerAudioPolicy(AudioPolicy policy) |
void |
registerAudioPortUpdateListener(AudioManager.OnAudioPortUpdateListener l)
Register an audio port list update listener.
|
void |
registerAudioRecordingCallback(AudioManager.AudioRecordingCallback cb,
Handler handler)
Register a callback to be notified of audio recording changes through
AudioManager.AudioRecordingCallback |
void |
registerMediaButtonEventReceiver(ComponentName eventReceiver)
Deprecated.
Use
MediaSession.setMediaButtonReceiver(PendingIntent) instead. |
void |
registerMediaButtonEventReceiver(PendingIntent eventReceiver)
Deprecated.
Use
MediaSession.setMediaButtonReceiver(PendingIntent) instead. |
void |
registerMediaButtonIntent(PendingIntent pi,
ComponentName eventReceiver) |
void |
registerRemoteControlClient(RemoteControlClient rcClient)
Deprecated.
Use
MediaSession instead. |
boolean |
registerRemoteController(RemoteController rctlr)
|
static int |
releaseAudioPatch(AudioPatch patch)
Releases an existing audio patch connection.
|
void |
reloadAudioSettings() |
int |
requestAudioFocus(AudioManager.OnAudioFocusChangeListener l,
AudioAttributes requestAttributes,
int durationHint,
int flags) |
int |
requestAudioFocus(AudioManager.OnAudioFocusChangeListener l,
AudioAttributes requestAttributes,
int durationHint,
int flags,
AudioPolicy ap) |
int |
requestAudioFocus(AudioManager.OnAudioFocusChangeListener l,
int streamType,
int durationHint)
Request audio focus.
|
void |
requestAudioFocusForCall(int streamType,
int durationHint) |
static int |
setAudioPortGain(AudioPort port,
AudioGainConfig gain)
Set the gain on the specified AudioPort.
|
int |
setBluetoothA2dpDeviceConnectionState(BluetoothDevice device,
int state,
int profile)
Indicate A2DP source or sink connection state change.
|
void |
setBluetoothA2dpOn(boolean on)
Deprecated.
Do not use.
|
void |
setBluetoothScoOn(boolean on)
Request use of Bluetooth SCO headset for communications.
|
int |
setHdmiSystemAudioSupported(boolean on)
Set Hdmi Cec system audio mode.
|
void |
setMasterMute(boolean mute,
int flags) |
void |
setMicrophoneMute(boolean on)
Sets the microphone mute on or off.
|
void |
setMode(int mode)
Sets the audio mode.
|
void |
setParameter(String key,
String value)
Deprecated.
Use
setParameters(String) instead |
void |
setParameters(String keyValuePairs)
Sets a variable number of parameter values to audio hardware.
|
void |
setRingerMode(int ringerMode)
Sets the ringer mode.
|
void |
setRingerModeInternal(int ringerMode)
Only useful for volume controllers.
|
void |
setRouting(int mode,
int routes,
int mask)
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)
Deprecated.
Use
adjustStreamVolume(int, int, int) with
ADJUST_MUTE or ADJUST_UNMUTE instead. |
void |
setStreamSolo(int streamType,
boolean state)
Deprecated.
Do not use. If you need exclusive audio playback use
requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int) . |
void |
setStreamVolume(int streamType,
int index,
int flags)
Sets the volume index for a particular stream.
|
void |
setVibrateSetting(int vibrateType,
int vibrateSetting)
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode that can be queried via
getRingerMode() . |
void |
setVolumeController(IVolumeController controller)
Registers a global volume controller interface.
|
void |
setVolumePolicy(VolumePolicy policy)
Only useful for volume controllers.
|
void |
setWiredDeviceConnectionState(int type,
int state,
String address,
String name)
Indicate wired accessory connection state change.
|
void |
setWiredHeadsetOn(boolean on)
Deprecated.
Do not use.
|
boolean |
shouldVibrate(int vibrateType)
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 |
startBluetoothScoVirtualCall() |
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 |
unregisterAudioFocusListener(AudioManager.OnAudioFocusChangeListener l) |
void |
unregisterAudioPolicyAsync(AudioPolicy policy) |
void |
unregisterAudioPortUpdateListener(AudioManager.OnAudioPortUpdateListener l)
Unregister an audio port list update listener.
|
void |
unregisterAudioRecordingCallback(AudioManager.AudioRecordingCallback cb)
Unregister an audio recording callback previously registered with
registerAudioRecordingCallback(AudioRecordingCallback, Handler) . |
void |
unregisterMediaButtonEventReceiver(ComponentName eventReceiver)
Deprecated.
Use
MediaSession instead. |
void |
unregisterMediaButtonEventReceiver(PendingIntent eventReceiver)
Deprecated.
Use
MediaSession instead. |
void |
unregisterMediaButtonIntent(PendingIntent pi) |
void |
unregisterRemoteControlClient(RemoteControlClient rcClient)
Deprecated.
Use
MediaSession instead. |
void |
unregisterRemoteController(RemoteController rctlr)
|
public static final String ACTION_AUDIO_BECOMING_NOISY
public static final String RINGER_MODE_CHANGED_ACTION
EXTRA_RINGER_MODE
,
Constant Field Valuespublic static final String INTERNAL_RINGER_MODE_CHANGED_ACTION
EXTRA_RINGER_MODE
,
Constant Field Valuespublic static final String EXTRA_RINGER_MODE
public static final String VIBRATE_SETTING_CHANGED_ACTION
RINGER_MODE_CHANGED_ACTION
instead.public static final String VOLUME_CHANGED_ACTION
public static final String STREAM_DEVICES_CHANGED_ACTION
public static final String STREAM_MUTE_CHANGED_ACTION
public static final String MASTER_MUTE_CHANGED_ACTION
EXTRA_MASTER_VOLUME_MUTED
,
Constant Field Valuespublic static final String EXTRA_VIBRATE_SETTING
RINGER_MODE_CHANGED_ACTION
instead.public static final String EXTRA_VIBRATE_TYPE
RINGER_MODE_CHANGED_ACTION
instead.public static final String EXTRA_VOLUME_STREAM_TYPE
public static final String EXTRA_VOLUME_STREAM_TYPE_ALIAS
public static final String EXTRA_VOLUME_STREAM_VALUE
public static final String EXTRA_PREV_VOLUME_STREAM_VALUE
public static final String EXTRA_VOLUME_STREAM_DEVICES
public static final String EXTRA_PREV_VOLUME_STREAM_DEVICES
public static final String EXTRA_MASTER_VOLUME_MUTED
public static final String EXTRA_STREAM_VOLUME_MUTED
public static final String ACTION_HEADSET_PLUG
Context.registerReceiver()
.
The intent will have the following extra values:
public static final String ACTION_HDMI_AUDIO_PLUG
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)
.
public static final String EXTRA_AUDIO_PLUG_STATE
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.public static final String EXTRA_MAX_CHANNEL_COUNT
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
).public static final String EXTRA_ENCODINGS
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.public static final int STREAM_VOICE_CALL
public static final int STREAM_SYSTEM
public static final int STREAM_RING
public static final int STREAM_MUSIC
public static final int STREAM_ALARM
public static final int STREAM_NOTIFICATION
public static final int STREAM_BLUETOOTH_SCO
public static final int STREAM_SYSTEM_ENFORCED
public static final int STREAM_DTMF
public static final int STREAM_TTS
@Deprecated public static final int NUM_STREAMS
public static final int ADJUST_RAISE
public static final int ADJUST_LOWER
public static final int ADJUST_SAME
public static final int ADJUST_MUTE
public static final int ADJUST_UNMUTE
public static final int ADJUST_TOGGLE_MUTE
public static final int FLAG_SHOW_UI
public static final int FLAG_ALLOW_RINGER_MODES
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.
public static final int FLAG_PLAY_SOUND
If this is given to adjustVolume(int, int)
or
adjustSuggestedStreamVolume(int, int, int)
, it may be ignored
in some cases (for example, the decided stream type is not
STREAM_RING
, or the volume is being adjusted
downward).
public static final int FLAG_REMOVE_SOUND_AND_VIBRATE
public static final int FLAG_VIBRATE
public static final int FLAG_FIXED_VOLUME
public static final int FLAG_BLUETOOTH_ABS_VOLUME
public static final int FLAG_SHOW_SILENT_HINT
public static final int FLAG_HDMI_SYSTEM_AUDIO_VOLUME
public static final int FLAG_ACTIVE_MEDIA_ONLY
public static final int FLAG_SHOW_UI_WARNINGS
public static final int FLAG_SHOW_VIBRATE_HINT
public static final int FLAG_FROM_KEY
public static final int RINGER_MODE_SILENT
setRingerMode(int)
,
getRingerMode()
,
Constant Field Valuespublic static final int RINGER_MODE_VIBRATE
setRingerMode(int)
,
getRingerMode()
,
Constant Field Valuespublic static final int RINGER_MODE_NORMAL
setRingerMode(int)
,
getRingerMode()
,
Constant Field Valuespublic static final int RINGER_MODE_MAX
public static final int VIBRATE_TYPE_RINGER
getRingerMode()
.public static final int VIBRATE_TYPE_NOTIFICATION
getRingerMode()
.public static final int VIBRATE_SETTING_OFF
getRingerMode()
.public static final int VIBRATE_SETTING_ON
getRingerMode()
.public static final int VIBRATE_SETTING_ONLY_SILENT
getRingerMode()
.public static final int USE_DEFAULT_STREAM_TYPE
@Deprecated public static final String ACTION_SCO_AUDIO_STATE_CHANGED
ACTION_SCO_AUDIO_STATE_UPDATED
insteadEXTRA_SCO_AUDIO_STATE
indicating the new state which is either SCO_AUDIO_STATE_DISCONNECTED
or SCO_AUDIO_STATE_CONNECTED
startBluetoothSco()
,
Constant Field Valuespublic static final String ACTION_SCO_AUDIO_STATE_UPDATED
This intent has two extras:
EXTRA_SCO_AUDIO_STATE
- The new SCO audio state. EXTRA_SCO_AUDIO_PREVIOUS_STATE
- The previous SCO audio state. EXTRA_SCO_AUDIO_STATE or EXTRA_SCO_AUDIO_PREVIOUS_STATE can be any of:
startBluetoothSco()
,
Constant Field Valuespublic static final String EXTRA_SCO_AUDIO_STATE
ACTION_SCO_AUDIO_STATE_CHANGED
or
ACTION_SCO_AUDIO_STATE_UPDATED
containing the new bluetooth SCO connection state.public static final String EXTRA_SCO_AUDIO_PREVIOUS_STATE
ACTION_SCO_AUDIO_STATE_UPDATED
containing the previous
bluetooth SCO connection state.public static final int SCO_AUDIO_STATE_DISCONNECTED
public static final int SCO_AUDIO_STATE_CONNECTED
EXTRA_SCO_AUDIO_STATE
or EXTRA_SCO_AUDIO_PREVIOUS_STATE
indicating that the SCO audio channel is establishedpublic static final int SCO_AUDIO_STATE_CONNECTING
public static final int SCO_AUDIO_STATE_ERROR
public static final int MODE_INVALID
public static final int MODE_CURRENT
public static final int MODE_NORMAL
public static final int MODE_RINGTONE
public static final int MODE_IN_CALL
public static final int MODE_IN_COMMUNICATION
@Deprecated public static final int ROUTE_EARPIECE
@Deprecated public static final int ROUTE_SPEAKER
@Deprecated public static final int ROUTE_BLUETOOTH
ROUTE_BLUETOOTH_SCO
@Deprecated public static final int ROUTE_BLUETOOTH_SCO
@Deprecated public static final int ROUTE_HEADSET
@Deprecated public static final int ROUTE_BLUETOOTH_A2DP
@Deprecated public static final int ROUTE_ALL
setRouting(int,int,int)
.public static final int AUDIO_SESSION_ID_GENERATE
AudioTrack
instance with
AudioTrack.AudioTrack(AudioAttributes, AudioFormat, int, int, int)
.public static final int FX_KEY_CLICK
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_FOCUS_NAVIGATION_UP
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_FOCUS_NAVIGATION_DOWN
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_FOCUS_NAVIGATION_LEFT
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_FOCUS_NAVIGATION_RIGHT
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_KEYPRESS_STANDARD
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_KEYPRESS_SPACEBAR
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_KEYPRESS_DELETE
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_KEYPRESS_RETURN
playSoundEffect(int)
,
Constant Field Valuespublic static final int FX_KEYPRESS_INVALID
playSoundEffect(int)
,
Constant Field Valuespublic static final int NUM_SOUND_EFFECTS
public static final int AUDIOFOCUS_NONE
public static final int AUDIOFOCUS_GAIN
public static final int AUDIOFOCUS_GAIN_TRANSIENT
public static final int AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
public static final int AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
public static final int AUDIOFOCUS_LOSS
public static final int AUDIOFOCUS_LOSS_TRANSIENT
public static final int AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
public static final int AUDIOFOCUS_REQUEST_FAILED
public static final int AUDIOFOCUS_REQUEST_GRANTED
public static final int AUDIOFOCUS_REQUEST_DELAYED
public static final int AUDIOFOCUS_FLAG_DELAY_OK
public static final int AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS
public static final int AUDIOFOCUS_FLAG_LOCK
public static final int AUDIOFOCUS_FLAGS_APPS
public static final int AUDIOFOCUS_FLAGS_SYSTEM
public static final int RECORD_CONFIG_EVENT_START
public static final int RECORD_CONFIG_EVENT_STOP
public static final int DEVICE_NONE
public static final int DEVICE_OUT_EARPIECE
public static final int DEVICE_OUT_SPEAKER
public static final int DEVICE_OUT_WIRED_HEADSET
public static final int DEVICE_OUT_WIRED_HEADPHONE
public static final int DEVICE_OUT_BLUETOOTH_SCO
public static final int DEVICE_OUT_BLUETOOTH_SCO_HEADSET
public static final int DEVICE_OUT_BLUETOOTH_SCO_CARKIT
public static final int DEVICE_OUT_BLUETOOTH_A2DP
public static final int DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES
public static final int DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER
public static final int DEVICE_OUT_AUX_DIGITAL
public static final int DEVICE_OUT_HDMI
public static final int DEVICE_OUT_ANLG_DOCK_HEADSET
public static final int DEVICE_OUT_DGTL_DOCK_HEADSET
public static final int DEVICE_OUT_USB_ACCESSORY
public static final int DEVICE_OUT_USB_DEVICE
public static final int DEVICE_OUT_REMOTE_SUBMIX
public static final int DEVICE_OUT_TELEPHONY_TX
public static final int DEVICE_OUT_LINE
public static final int DEVICE_OUT_HDMI_ARC
public static final int DEVICE_OUT_SPDIF
public static final int DEVICE_OUT_FM
public static final int DEVICE_OUT_DEFAULT
public static final int DEVICE_IN_BUILTIN_MIC
public static final int DEVICE_IN_BLUETOOTH_SCO_HEADSET
public static final int DEVICE_IN_WIRED_HEADSET
public static final int DEVICE_IN_HDMI
public static final int DEVICE_IN_TELEPHONY_RX
public static final int DEVICE_IN_BACK_MIC
public static final int DEVICE_IN_ANLG_DOCK_HEADSET
public static final int DEVICE_IN_DGTL_DOCK_HEADSET
public static final int DEVICE_IN_USB_ACCESSORY
public static final int DEVICE_IN_USB_DEVICE
public static final int DEVICE_IN_FM_TUNER
public static final int DEVICE_IN_TV_TUNER
public static final int DEVICE_IN_LINE
public static final int DEVICE_IN_SPDIF
public static final int DEVICE_IN_LOOPBACK
public static final String PROPERTY_OUTPUT_SAMPLE_RATE
getProperty(java.lang.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.public static final String PROPERTY_OUTPUT_FRAMES_PER_BUFFER
getProperty(java.lang.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.public static final String PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND
getProperty(java.lang.String)
to determine if the default microphone audio source
supports near-ultrasound frequencies (range of 18 - 21 kHz).public static final String PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND
getProperty(java.lang.String)
to determine if the default speaker audio path
supports near-ultrasound frequencies (range of 18 - 21 kHz).public static final String PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED
getProperty(java.lang.String)
to determine if the unprocessed audio source is
available and supported with the expected frequency range and level response.public static final int SUCCESS
public static final int ERROR
public static final int ERROR_BAD_VALUE
public static final int ERROR_INVALID_OPERATION
public static final int ERROR_PERMISSION_DENIED
public static final int ERROR_NO_INIT
public static final int ERROR_DEAD_OBJECT
public static final int GET_DEVICES_INPUTS
getDevices(int)
method to include
source (i.e. input) audio devices.public static final int GET_DEVICES_OUTPUTS
getDevices(int)
method to include
sink (i.e. output) audio devices.public static final int GET_DEVICES_ALL
getDevices(int)
method to include both
source and sink devices.public AudioManager(Context context)
public static String flagsToString(int flags)
public void dispatchMediaKeyEvent(KeyEvent keyEvent)
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
registerMediaButtonEventReceiver(PendingIntent)
.
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
.public void preDispatchKeyEvent(KeyEvent event, int stream)
public void handleKeyDown(KeyEvent event, int stream)
public void handleKeyUp(KeyEvent event, int stream)
public boolean isVolumeFixed()
Some devices may not have volume control and may operate at a fixed volume, and may not enable muting or changing the volume of audio streams. This method will return true on such devices.
The following APIs have no effect when volume is fixed:
public void adjustStreamVolume(int streamType, int direction, int flags)
This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.
streamType
- The stream type to adjust. One of STREAM_VOICE_CALL
,
STREAM_SYSTEM
, STREAM_RING
, STREAM_MUSIC
or
STREAM_ALARM
direction
- The direction to adjust the volume. One of
ADJUST_LOWER
, ADJUST_RAISE
, or
ADJUST_SAME
.flags
- One or more flags.adjustVolume(int, int)
,
setStreamVolume(int, int, int)
public void adjustVolume(int direction, int flags)
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()
.
direction
- The direction to adjust the volume. One of
ADJUST_LOWER
, ADJUST_RAISE
,
ADJUST_SAME
, ADJUST_MUTE
,
ADJUST_UNMUTE
, or ADJUST_TOGGLE_MUTE
.flags
- One or more flags.adjustSuggestedStreamVolume(int, int, int)
,
adjustStreamVolume(int, int, int)
,
setStreamVolume(int, int, int)
,
isVolumeFixed()
public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags)
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()
.
direction
- The direction to adjust the volume. One of
ADJUST_LOWER
, ADJUST_RAISE
,
ADJUST_SAME
, ADJUST_MUTE
,
ADJUST_UNMUTE
, or ADJUST_TOGGLE_MUTE
.suggestedStreamType
- The stream type that will be used if there
isn't a relevant stream. USE_DEFAULT_STREAM_TYPE
is
valid here.flags
- One or more flags.adjustVolume(int, int)
,
adjustStreamVolume(int, int, int)
,
setStreamVolume(int, int, int)
,
isVolumeFixed()
public void setMasterMute(boolean mute, int flags)
public int getRingerMode()
RINGER_MODE_NORMAL
,
RINGER_MODE_SILENT
, or RINGER_MODE_VIBRATE
.setRingerMode(int)
public static boolean isValidRingerMode(int ringerMode)
setRingerMode(int)
public int getStreamMaxVolume(int streamType)
streamType
- The stream type whose maximum volume index is returned.getStreamVolume(int)
public int getStreamMinVolume(int streamType)
streamType
- The stream type whose minimum volume index is returned.getStreamVolume(int)
public int getStreamVolume(int streamType)
streamType
- The stream type whose volume index is returned.getStreamMaxVolume(int)
,
setStreamVolume(int, int, int)
public int getLastAudibleStreamVolume(int streamType)
public int getUiSoundsStreamType()
public void setRingerMode(int ringerMode)
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()
.
ringerMode
- The ringer mode, one of RINGER_MODE_NORMAL
,
RINGER_MODE_SILENT
, or RINGER_MODE_VIBRATE
.getRingerMode()
,
isVolumeFixed()
public void setStreamVolume(int streamType, int index, int flags)
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()
.
streamType
- The stream whose volume index should be set.index
- The volume index to set. See
getStreamMaxVolume(int)
for the largest valid value.flags
- One or more flags.getStreamMaxVolume(int)
,
getStreamVolume(int)
,
isVolumeFixed()
@Deprecated public void setStreamSolo(int streamType, boolean state)
requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int)
.
Do not use. This method has been deprecated and is now a no-op.
requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int)
should be used for exclusive audio playback.
streamType
- The stream to be soloed/unsoloed.state
- The required solo state: true for solo ON, false for solo
OFFisVolumeFixed()
@Deprecated public void setStreamMute(int streamType, boolean state)
adjustStreamVolume(int, int, int)
with
ADJUST_MUTE
or ADJUST_UNMUTE
instead.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:
streamType
- The stream to be muted/unmuted.state
- The required mute state: true for mute ON, false for mute
OFFisVolumeFixed()
public boolean isStreamMute(int streamType)
streamType
- The stream to get mute state for.adjustStreamVolume(int, int, int)
public boolean isMasterMute()
public void forceVolumeControlStream(int streamType)
public boolean shouldVibrate(int vibrateType)
getRingerMode()
.This shouldn't be needed by most clients that use notifications to vibrate. The notification manager will not vibrate if the policy doesn't allow it, so the client should always set a vibrate pattern and let the notification manager control whether or not to actually vibrate.
vibrateType
- The type of vibrate. One of
VIBRATE_TYPE_NOTIFICATION
or
VIBRATE_TYPE_RINGER
.setVibrateSetting(int, int)
,
getVibrateSetting(int)
public int getVibrateSetting(int vibrateType)
getRingerMode()
.
This shouldn't be needed by most clients that want to vibrate, instead
see shouldVibrate(int)
.
vibrateType
- The type of vibrate. One of
VIBRATE_TYPE_NOTIFICATION
or
VIBRATE_TYPE_RINGER
.VIBRATE_SETTING_ON
,
VIBRATE_SETTING_OFF
, or
VIBRATE_SETTING_ONLY_SILENT
.setVibrateSetting(int, int)
,
shouldVibrate(int)
public void setVibrateSetting(int vibrateType, int vibrateSetting)
getRingerMode()
.This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.
vibrateType
- The type of vibrate. One of
VIBRATE_TYPE_NOTIFICATION
or
VIBRATE_TYPE_RINGER
.vibrateSetting
- The vibrate setting, one of
VIBRATE_SETTING_ON
,
VIBRATE_SETTING_OFF
, or
VIBRATE_SETTING_ONLY_SILENT
.getVibrateSetting(int)
,
shouldVibrate(int)
public void setSpeakerphoneOn(boolean on)
This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.
on
- set true to turn on speakerphone;
false to turn it offpublic boolean isSpeakerphoneOn()
public boolean isBluetoothScoAvailableOffCall()
startBluetoothSco()
public void startBluetoothSco()
Requires Permission:
android.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:
STREAM_VOICE_CALL
The following restrictions apply on input streams:
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.
stopBluetoothSco()
,
ACTION_SCO_AUDIO_STATE_UPDATED
public void startBluetoothScoVirtualCall()
public void stopBluetoothSco()
Requires Permission:
android.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.
startBluetoothSco()
public void setBluetoothScoOn(boolean on)
This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.
on
- set true to use bluetooth SCO for communications;
false to not use bluetooth SCO for communicationspublic boolean isBluetoothScoOn()
@Deprecated public void setBluetoothA2dpOn(boolean on)
on
- set true to route A2DP audio to/from Bluetooth
headset; false disable A2DP audiopublic boolean isBluetoothA2dpOn()
@Deprecated public void setWiredHeadsetOn(boolean on)
on
- set true to route audio to/from wired
headset; false disable wired headset audiopublic boolean isWiredHeadsetOn()
This is not a valid indication that audio playback is actually over the wired headset as audio routing depends on other conditions.
public void setMicrophoneMute(boolean on)
This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.
on
- set true to mute the microphone;
false to turn mute offpublic boolean isMicrophoneMute()
public void setMode(int 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.
mode
- the requested audio mode (MODE_NORMAL
, MODE_RINGTONE
,
MODE_IN_CALL
or MODE_IN_COMMUNICATION
).
Informs the HAL about the current audio state so that
it can route the audio appropriately.public int getMode()
MODE_NORMAL
, MODE_RINGTONE
,
MODE_IN_CALL
or MODE_IN_COMMUNICATION
).
Returns the current current audio state from the HAL.@Deprecated public void setRouting(int mode, int routes, int mask)
mode
- audio mode to change route. E.g., MODE_RINGTONE.routes
- bit vector of routes requested, created from one or
more of ROUTE_xxx types. Set bits indicate that route should be onmask
- bit vector of routes to change, created from one or more of
ROUTE_xxx types. Unset bits indicate the route should be left unchanged@Deprecated public int getRouting(int mode)
mode
- audio mode to get route (e.g., MODE_RINGTONE)public boolean isMusicActive()
public boolean isMusicActiveRemotely()
STREAM_MUSIC
is active on a remote devicepublic boolean isAudioFocusExclusive()
AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
public int generateAudioSessionId()
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
.
ERROR
when the
system failed to generate a new session, a condition in which audio playback or recording
will subsequently fail as well.@Deprecated public void setParameter(String key, String value)
setParameters(String)
insteadpublic void setParameters(String keyValuePairs)
keyValuePairs
- list of parameters key value pairs in the form:
key1=value1;key2=value2;...public String getParameters(String keys)
keys
- list of parameterspublic void playSoundEffect(int effectType)
effectType
- The type of sound effect. One of
FX_KEY_CLICK
,
FX_FOCUS_NAVIGATION_UP
,
FX_FOCUS_NAVIGATION_DOWN
,
FX_FOCUS_NAVIGATION_LEFT
,
FX_FOCUS_NAVIGATION_RIGHT
,
FX_KEYPRESS_STANDARD
,
FX_KEYPRESS_SPACEBAR
,
FX_KEYPRESS_DELETE
,
FX_KEYPRESS_RETURN
,
FX_KEYPRESS_INVALID
,
NOTE: This version uses the UI settings to determine
whether sounds are heard or not.public void playSoundEffect(int effectType, int userId)
effectType
- The type of sound effect. One of
FX_KEY_CLICK
,
FX_FOCUS_NAVIGATION_UP
,
FX_FOCUS_NAVIGATION_DOWN
,
FX_FOCUS_NAVIGATION_LEFT
,
FX_FOCUS_NAVIGATION_RIGHT
,
FX_KEYPRESS_STANDARD
,
FX_KEYPRESS_SPACEBAR
,
FX_KEYPRESS_DELETE
,
FX_KEYPRESS_RETURN
,
FX_KEYPRESS_INVALID
,userId
- The current user to pull sound settings from
NOTE: This version uses the UI settings to determine
whether sounds are heard or not.public void playSoundEffect(int effectType, float volume)
effectType
- The type of sound effect. One of
FX_KEY_CLICK
,
FX_FOCUS_NAVIGATION_UP
,
FX_FOCUS_NAVIGATION_DOWN
,
FX_FOCUS_NAVIGATION_LEFT
,
FX_FOCUS_NAVIGATION_RIGHT
,
FX_KEYPRESS_STANDARD
,
FX_KEYPRESS_SPACEBAR
,
FX_KEYPRESS_DELETE
,
FX_KEYPRESS_RETURN
,
FX_KEYPRESS_INVALID
,volume
- Sound effect volume.
The volume value is a raw scalar so UI controls should be scaled logarithmically.
If a volume of -1 is specified, the AudioManager.STREAM_MUSIC stream volume minus 3dB will be used.
NOTE: This version is for applications that have their own
settings panel for enabling and controlling volume.public void loadSoundEffects()
public void unloadSoundEffects()
public void registerAudioFocusListener(AudioManager.OnAudioFocusChangeListener l)
l
- the listener to be notified of audio focus changes.public void unregisterAudioFocusListener(AudioManager.OnAudioFocusChangeListener l)
l
- the listener to unregister.public int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint)
l
- the listener to be notified of audio focus changesstreamType
- the main audio stream type affected by the focus requestdurationHint
- 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.AUDIOFOCUS_REQUEST_FAILED
or AUDIOFOCUS_REQUEST_GRANTED
public int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, AudioAttributes requestAttributes, int durationHint, int flags) throws IllegalArgumentException
l
- the listener to be notified of audio focus changes. It is not allowed to be null
when the request is flagged with AUDIOFOCUS_FLAG_DELAY_OK
.requestAttributes
- non null AudioAttributes
describing the main reason for
requesting audio focus.durationHint
- use AUDIOFOCUS_GAIN_TRANSIENT
to indicate this focus request
is temporary, and focus will be abandonned shortly. Examples of transient requests are
for the playback of driving directions, or notifications sounds.
Use AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
to indicate also that it's ok for
the previous focus owner to keep playing if it ducks its audio output.
Alternatively use AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
for a temporary request
that benefits from the system not playing disruptive sounds like notifications, for
usecases such as voice memo recording, or speech recognition.
Use AUDIOFOCUS_GAIN
for a focus request of unknown duration such
as the playback of a song or a video.flags
- 0 or a combination of {link #AUDIOFOCUS_FLAG_DELAY_OK}
and AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS
.
requestAudioFocus(OnAudioFocusChangeListener, int, int)
, where either audio
focus is granted immediately, or the grant request fails because the system is in a
state where focus cannot change (e.g. a phone call).AUDIOFOCUS_REQUEST_FAILED
, AUDIOFOCUS_REQUEST_GRANTED
or AUDIOFOCUS_REQUEST_DELAYED
.
The return value is never AUDIOFOCUS_REQUEST_DELAYED
when focus is requested
without the AUDIOFOCUS_FLAG_DELAY_OK
flag.IllegalArgumentException
public int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l, AudioAttributes requestAttributes, int durationHint, int flags, AudioPolicy ap) throws IllegalArgumentException
l
- see the description of the same parameter in
requestAudioFocus(OnAudioFocusChangeListener, AudioAttributes, int, int)
requestAttributes
- non null AudioAttributes
describing the main reason for
requesting audio focus.durationHint
- see the description of the same parameter in
requestAudioFocus(OnAudioFocusChangeListener, AudioAttributes, int, int)
flags
- 0 or a combination of {link #AUDIOFOCUS_FLAG_DELAY_OK},
AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS
, and AUDIOFOCUS_FLAG_LOCK
.
requestAudioFocus(OnAudioFocusChangeListener, int, int)
, where either audio
focus is granted immediately, or the grant request fails because the system is in a
state where focus cannot change (e.g. a phone call).ap
- a registered AudioPolicy
instance when locking
focus, or null.requestAudioFocus(OnAudioFocusChangeListener, AudioAttributes, int, int)
IllegalArgumentException
public void requestAudioFocusForCall(int streamType, int durationHint)
streamType
- use STREAM_RING for focus requests when ringing, VOICE_CALL for
the establishment of the calldurationHint
- the type of focus request. AUDIOFOCUS_GAIN_TRANSIENT is recommended so
media applications resume after a callpublic void abandonAudioFocusForCall()
public int abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l)
l
- the listener with which focus was requested.AUDIOFOCUS_REQUEST_FAILED
or AUDIOFOCUS_REQUEST_GRANTED
public int abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l, AudioAttributes aa)
l
- the listener with which focus was requested.aa
- the AudioAttributes
with which audio focus was requestedAUDIOFOCUS_REQUEST_FAILED
or AUDIOFOCUS_REQUEST_GRANTED
@Deprecated public void registerMediaButtonEventReceiver(ComponentName eventReceiver)
MediaSession.setMediaButtonReceiver(PendingIntent)
instead.eventReceiver
- identifier of a BroadcastReceiver
that will receive the media button intent. This broadcast receiver must be declared
in the application manifest. The package of the component must match that of
the context you're registering from.@Deprecated public void registerMediaButtonEventReceiver(PendingIntent eventReceiver)
MediaSession.setMediaButtonReceiver(PendingIntent)
instead.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.eventReceiver
- 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.public void registerMediaButtonIntent(PendingIntent pi, ComponentName eventReceiver)
@Deprecated public void unregisterMediaButtonEventReceiver(ComponentName eventReceiver)
MediaSession
instead.eventReceiver
- identifier of a BroadcastReceiver
that was registered with registerMediaButtonEventReceiver(ComponentName)
.@Deprecated public void unregisterMediaButtonEventReceiver(PendingIntent eventReceiver)
MediaSession
instead.eventReceiver
- same PendingIntent that was registed with
registerMediaButtonEventReceiver(PendingIntent)
.public void unregisterMediaButtonIntent(PendingIntent pi)
@Deprecated public void registerRemoteControlClient(RemoteControlClient rcClient)
MediaSession
instead.rcClient
- The remote control client from which remote controls will receive
information to display.RemoteControlClient
@Deprecated public void unregisterRemoteControlClient(RemoteControlClient rcClient)
MediaSession
instead.rcClient
- The remote control client to unregister.registerRemoteControlClient(RemoteControlClient)
@Deprecated public boolean registerRemoteController(RemoteController rctlr)
MediaSessionManager.addOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener, ComponentName)
and MediaController
instead.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
).
rctlr
- the object to register.RemoteController
was successfully registered,
false if an error occurred, due to an internal system error, or
insufficient permissions.@Deprecated public void unregisterRemoteController(RemoteController rctlr)
MediaSessionManager.removeOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener)
instead.RemoteController
, causing it to no longer receive
media metadata and playback state information, and no longer be capable
of controlling playback.rctlr
- the object to unregister.public int registerAudioPolicy(AudioPolicy policy)
policy
- the non-null AudioPolicy
to register.ERROR
if there was an error communicating with the registration service
or if the user doesn't have the required
android.Manifest.permission#MODIFY_AUDIO_ROUTING
permission,
SUCCESS
otherwise.public void unregisterAudioPolicyAsync(AudioPolicy policy)
policy
- the non-null AudioPolicy
to unregister.public void registerAudioRecordingCallback(AudioManager.AudioRecordingCallback cb, Handler handler)
AudioManager.AudioRecordingCallback
public void unregisterAudioRecordingCallback(AudioManager.AudioRecordingCallback cb)
registerAudioRecordingCallback(AudioRecordingCallback, Handler)
.cb
- non-null callback to unregisterpublic List<AudioRecordingConfiguration> getActiveRecordingConfigurations()
AudioRecordingConfiguration
public void reloadAudioSettings()
public void avrcpSupportsAbsoluteVolume(String address, boolean support)
public boolean isSilentMode()
getRingerMode()
public static boolean isOutputDevice(int device)
public static boolean isInputDevice(int device)
public int getDevicesForStream(int streamType)
streamType
- The stream type to query. One of
STREAM_VOICE_CALL
,
STREAM_SYSTEM
,
STREAM_RING
,
STREAM_MUSIC
,
STREAM_ALARM
,
STREAM_NOTIFICATION
,
STREAM_DTMF
.DEVICE_OUT_EARPIECE
,
DEVICE_OUT_SPEAKER
,
DEVICE_OUT_WIRED_HEADSET
,
DEVICE_OUT_WIRED_HEADPHONE
,
DEVICE_OUT_BLUETOOTH_SCO
,
DEVICE_OUT_BLUETOOTH_SCO_HEADSET
,
DEVICE_OUT_BLUETOOTH_SCO_CARKIT
,
DEVICE_OUT_BLUETOOTH_A2DP
,
DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES
,
DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER
,
DEVICE_OUT_HDMI
,
DEVICE_OUT_ANLG_DOCK_HEADSET
,
DEVICE_OUT_DGTL_DOCK_HEADSET
.
DEVICE_OUT_USB_ACCESSORY
.
DEVICE_OUT_USB_DEVICE
.
DEVICE_OUT_REMOTE_SUBMIX
.
DEVICE_OUT_TELEPHONY_TX
.
DEVICE_OUT_LINE
.
DEVICE_OUT_HDMI_ARC
.
DEVICE_OUT_SPDIF
.
DEVICE_OUT_FM
.
DEVICE_OUT_DEFAULT
is not used here.
The implementation may support additional device codes beyond those listed, so
the application should ignore any bits which it does not recognize.
Note that the information may be imprecise when the implementation
cannot distinguish whether a particular device is enabled.
public void setWiredDeviceConnectionState(int type, int state, String address, String name)
device
- type of device connected/disconnected (AudioManager.DEVICE_OUT_xxx)state
- new connection state: 1 connected, 0 disconnectedname
- device name
public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device, int state, int profile)
device
- Bluetooth device connected/disconnectedstate
- new connection state (BluetoothProfile.STATE_xxx)profile
- profile for the A2DP device
(either android.bluetooth.BluetoothProfile.A2DP
or
android.bluetooth.BluetoothProfile.A2DP_SINK
)public IRingtonePlayer getRingtonePlayer()
public String getProperty(String key)
key
- 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
.public int getOutputLatency(int streamType)
public void setVolumeController(IVolumeController controller)
public void notifyVolumeControllerVisible(IVolumeController controller, boolean visible)
public boolean isStreamAffectedByRingerMode(int streamType)
public boolean isStreamAffectedByMute(int streamType)
public void disableSafeMediaVolume()
public void setRingerModeInternal(int ringerMode)
public int getRingerModeInternal()
public void setVolumePolicy(VolumePolicy policy)
public int setHdmiSystemAudioSupported(boolean on)
on
- whether to be on system audio modepublic boolean isHdmiSystemAudioSupported()
public static int listAudioPorts(ArrayList<AudioPort> ports)
ports
- An AudioPort ArrayList where the list will be returned.public static int listPreviousAudioPorts(ArrayList<AudioPort> ports)
ports
- An AudioPort ArrayList where the list will be returned.public static int listAudioDevicePorts(ArrayList<AudioDevicePort> devices)
listAudioPorts(ArrayList)
public static int listPreviousAudioDevicePorts(ArrayList<AudioDevicePort> devices)
listPreviousAudioPorts(ArrayList)
public static int createAudioPatch(AudioPatch[] patch, AudioPortConfig[] sources, AudioPortConfig[] sinks)
patch
- AudioPatch array where the newly created patch will be returned.
As input, if patch[0] is not null, the specified patch will be replaced by the
new patch created. This avoids calling releaseAudioPatch() when modifying a
patch and allows the implementation to optimize transitions.sources
- List of source audio ports. All must be AudioPort.ROLE_SOURCE.sinks
- List of sink audio ports. All must be AudioPort.ROLE_SINK.SUCCESS
if connection is successful.
- ERROR_BAD_VALUE
if incompatible device types are passed.
- ERROR_INVALID_OPERATION
if the requested connection is not supported.
- ERROR_PERMISSION_DENIED
if the client does not have permission to create
a patch.
- ERROR_DEAD_OBJECT
if the server process is dead
- ERROR
if patch cannot be connected for any other reason.
patch[0] contains the newly created patchpublic static int releaseAudioPatch(AudioPatch patch)
patch
- The audio patch to disconnect.SUCCESS
if disconnection is successful.
- ERROR_BAD_VALUE
if the specified patch does not exist.
- ERROR_PERMISSION_DENIED
if the client does not have permission to release
a patch.
- ERROR_DEAD_OBJECT
if the server process is dead
- ERROR
if patch cannot be released for any other reason.public static int listAudioPatches(ArrayList<AudioPatch> patches)
patches
- An AudioPatch array where the list will be returned.public static int setAudioPortGain(AudioPort port, AudioGainConfig gain)
public void registerAudioPortUpdateListener(AudioManager.OnAudioPortUpdateListener l)
public void unregisterAudioPortUpdateListener(AudioManager.OnAudioPortUpdateListener l)
public AudioDeviceInfo[] getDevices(int flags)
AudioDeviceInfo
objects corresponding to the audio devices
currently connected to the system and meeting the criteria specified in the
flags
parameter.flags
- A set of bitflags specifying the criteria to test.GET_DEVICES_OUTPUTS}, {@link GET_DEVICES_INPUTS} and {@link GET_DEVICES_ALL}.
public static AudioDeviceInfo[] getDevicesStatic(int flags)
flags
parameter.
This is an internal function. The public API front is getDevices(int).flags
- A set of bitflags specifying the criteria to test.GET_DEVICES_OUTPUTS}, {@link GET_DEVICES_INPUTS} and {@link GET_DEVICES_ALL}.
public void registerAudioDeviceCallback(AudioDeviceCallback callback, Handler handler)
AudioDeviceCallback
object to receive notifications of changes
to the set of connected audio devices.callback
- The AudioDeviceCallback
object to receive connect/disconnect
notifications.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.public void unregisterAudioDeviceCallback(AudioDeviceCallback callback)
AudioDeviceCallback
object which has been previously registered
to receive notifications of changes to the set of connected audio devices.callback
- The AudioDeviceCallback
object that was previously registered
with {@link AudioManager#registerAudioDeviceCallback) to be unregistered.