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 interface |
AudioManager.OnAudioFocusChangeListener
Interface definition for a callback to be invoked when the audio focus of the system is
updated.
|
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_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_RAISE
Increase the ringer volume.
|
static int |
ADJUST_SAME
Maintain the previous ringer volume.
|
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_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_REQUEST_FAILED
A failed focus change request.
|
static int |
AUDIOFOCUS_REQUEST_GRANTED
A successful focus change request.
|
static int[] |
DEFAULT_STREAM_VOLUME |
static int |
DEVICE_OUT_ANLG_DOCK_HEADSET
The audio output device code for an analog wired headset attached via a
docking station
|
static int |
DEVICE_OUT_AUX_DIGITAL
The audio output device code for S/PDIF or HDMI
|
static int |
DEVICE_OUT_BLUETOOTH_A2DP
The audio output device code for generic Bluetooth A2DP, for music
|
static int |
DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES
The audio output device code for Bluetooth A2DP headphones, for music
|
static int |
DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER
The audio output device code for Bluetooth A2DP external speaker, for music
|
static int |
DEVICE_OUT_BLUETOOTH_SCO
The audio output device code for generic Bluetooth SCO, for voice
|
static int |
DEVICE_OUT_BLUETOOTH_SCO_CARKIT
The audio output device code for Bluetooth SCO car audio, for voice
|
static int |
DEVICE_OUT_BLUETOOTH_SCO_HEADSET
The audio output device code for Bluetooth SCO Headset Profile (HSP) and
Hands-Free Profile (HFP), for voice
|
static int |
DEVICE_OUT_DEFAULT
This is not used as a returned value from
getDevicesForStream(int) , but could be
used in the future in a set method to select whatever default device is chosen by the
platform-specific implementation. |
static int |
DEVICE_OUT_DGTL_DOCK_HEADSET
The audio output device code for a digital wired headset attached via a
docking station
|
static int |
DEVICE_OUT_EARPIECE
The audio output device code for the small speaker at the front of the device used
when placing calls.
|
static int |
DEVICE_OUT_SPEAKER
The audio output device code for the built-in speaker
|
static int |
DEVICE_OUT_USB_ACCESSORY
The audio output device code for a USB audio accessory.
|
static int |
DEVICE_OUT_USB_DEVICE
The audio output device code for a USB audio device.
|
static int |
DEVICE_OUT_WIRED_HEADPHONE
The audio output device code for a wired headphone without attached microphone
|
static int |
DEVICE_OUT_WIRED_HEADSET
The audio output device code for a wired headset with attached microphone
|
static String |
EXTRA_MASTER_VOLUME_MUTED |
static String |
EXTRA_MASTER_VOLUME_VALUE |
static String |
EXTRA_PREV_MASTER_VOLUME_VALUE |
static String |
EXTRA_PREV_VOLUME_STREAM_VALUE |
static String |
EXTRA_REMOTE_CONTROL_CLIENT_GENERATION |
static String |
EXTRA_REMOTE_CONTROL_CLIENT_INFO_CHANGED |
static String |
EXTRA_REMOTE_CONTROL_CLIENT_NAME |
static String |
EXTRA_REMOTE_CONTROL_EVENT_RECEIVER |
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_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_TYPE |
static String |
EXTRA_VOLUME_STREAM_VALUE |
static int |
FLAG_ALLOW_RINGER_MODES
Whether to include ringer modes as possible options when changing 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_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_UI
Show a toast containing the current volume.
|
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_RETURN
IME return_keypress sound
|
static int |
FX_KEYPRESS_SPACEBAR
IME spacebar keypress sound
|
static int |
FX_KEYPRESS_STANDARD
IME standard keypress sound
|
static String |
MASTER_MUTE_CHANGED_ACTION |
static String |
MASTER_VOLUME_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 primary 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 primary output stream, in decimal Hz. |
static String |
REMOTE_CONTROL_CLIENT_CHANGED |
static String |
RINGER_MODE_CHANGED_ACTION
Sticky broadcast intent action indicating that the ringer mode has
changed.
|
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 int |
STREAM_DTMF
The audio stream for DTMF Tones
|
static int |
STREAM_MUSIC
The audio stream for music playback
|
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 |
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.
|
void |
abandonAudioFocusForCall() |
void |
adjustLocalOrRemoteStreamVolume(int streamType,
int direction) |
void |
adjustMasterVolume(int steps,
int flags)
Adjusts the master volume for the device's audio amplifier.
|
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 |
forceVolumeControlStream(int streamType)
forces the stream controlled by hard volume keys
specifying streamType == -1 releases control to the
logic.
|
int |
getDevicesForStream(int streamType)
Return the enabled devices for the specified output stream type.
|
int |
getLastAudibleMasterVolume()
Get last audible volume before master volume was muted.
|
int |
getLastAudibleStreamVolume(int streamType)
Get last audible volume before stream was muted.
|
int |
getMasterMaxVolume()
Returns the maximum volume index for master volume.
|
int |
getMasterStreamType()
Get the stream type whose volume is driving the UI sounds volume.
|
int |
getMasterVolume()
Returns the current volume index for master volume.
|
int |
getMode()
Returns the current audio mode.
|
String |
getParameters(String keys)
Sets a varaible number of parameter values to audio hardware.
|
String |
getProperty(String key)
Returns the value of the property with the specified key.
|
int |
getRingerMode()
Returns the current ringtone mode.
|
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 |
getStreamVolume(int streamType)
Returns the current volume index for a particular stream.
|
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 |
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 |
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 |
isSilentMode()
Checks whether the phone is in silent mode, with or without vibrate.
|
boolean |
isSpeakerphoneOn()
Checks whether the speakerphone is on or off.
|
boolean |
isSpeechRecognitionActive() |
boolean |
isStreamMute(int streamType)
get stream mute state.
|
static boolean |
isValidRingerMode(int ringerMode)
Checks valid ringer mode values.
|
boolean |
isWiredHeadsetOn()
Deprecated.
Use only to check is a headset is connected or not.
|
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 |
preDispatchKeyEvent(KeyEvent event,
int stream) |
void |
registerAudioFocusListener(AudioManager.OnAudioFocusChangeListener l) |
void |
registerMediaButtonEventReceiver(ComponentName eventReceiver)
Register a component to be the sole receiver of MEDIA_BUTTON intents.
|
void |
registerMediaButtonEventReceiverForCalls(ComponentName eventReceiver) |
void |
registerMediaButtonIntent(PendingIntent pi,
ComponentName eventReceiver) |
void |
registerRemoteControlClient(RemoteControlClient rcClient)
Registers the remote control client for providing information to display on the remote
controls.
|
void |
registerRemoteControlDisplay(IRemoteControlDisplay rcd) |
void |
reloadAudioSettings() |
void |
remoteControlDisplayUsesBitmapSize(IRemoteControlDisplay rcd,
int w,
int h) |
int |
requestAudioFocus(AudioManager.OnAudioFocusChangeListener l,
int streamType,
int durationHint)
Request audio focus.
|
void |
requestAudioFocusForCall(int streamType,
int durationHint) |
int |
setBluetoothA2dpDeviceConnectionState(BluetoothDevice device,
int state)
Indicate A2DP sink connection state change.
|
void |
setBluetoothA2dpOn(boolean on)
Deprecated.
Do not use.
|
void |
setBluetoothScoOn(boolean on)
Request use of Bluetooth SCO headset for communications.
|
void |
setMasterMute(boolean state)
set master mute state.
|
void |
setMasterMute(boolean state,
int flags)
set master mute state with optional flags.
|
void |
setMasterVolume(int index,
int flags)
Sets the volume index for master volume.
|
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
#setPrameters(String) instead |
void |
setParameters(String keyValuePairs)
Sets a variable number of parameter values to audio hardware.
|
void |
setRemoteSubmixOn(boolean on,
int address) |
void |
setRingerMode(int ringerMode)
Sets the ringer mode.
|
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)
Mute or unmute an audio stream.
|
void |
setStreamSolo(int streamType,
boolean state)
Solo or unsolo a particular stream.
|
void |
setStreamVolume(int streamType,
int index,
int flags)
Sets the volume index for a particular stream.
|
void |
setVibrateSetting(int vibrateType,
int vibrateSetting)
Deprecated.
Applications should maintain their own vibrate policy based on
current ringer mode that can be queried via
getRingerMode() . |
void |
setWiredDeviceConnectionState(int device,
int state,
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 |
stopBluetoothSco()
Stop bluetooth SCO audio connection.
|
void |
unloadSoundEffects()
Unload Sound effects.
|
void |
unregisterAudioFocusListener(AudioManager.OnAudioFocusChangeListener l) |
void |
unregisterMediaButtonEventReceiver(ComponentName eventReceiver)
Unregister the receiver of MEDIA_BUTTON intents.
|
void |
unregisterMediaButtonEventReceiverForCalls() |
void |
unregisterMediaButtonIntent(PendingIntent pi,
ComponentName eventReceiver) |
void |
unregisterRemoteControlClient(RemoteControlClient rcClient)
Unregisters the remote control client that was providing information to display on the
remote controls.
|
void |
unregisterRemoteControlDisplay(IRemoteControlDisplay rcd) |
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 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 MASTER_VOLUME_CHANGED_ACTION
public static final String MASTER_MUTE_CHANGED_ACTION
public 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_VALUE
public static final String EXTRA_PREV_VOLUME_STREAM_VALUE
public static final String EXTRA_MASTER_VOLUME_VALUE
public static final String EXTRA_PREV_MASTER_VOLUME_VALUE
public static final String EXTRA_MASTER_VOLUME_MUTED
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[] DEFAULT_STREAM_VOLUME
public static final int ADJUST_RAISE
public static final int ADJUST_LOWER
public static final int ADJUST_SAME
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 RINGER_MODE_SILENT
public static final int RINGER_MODE_VIBRATE
public static final int RINGER_MODE_NORMAL
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 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 NUM_SOUND_EFFECTS
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_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 String REMOTE_CONTROL_CLIENT_CHANGED
#EXTRA_REMOTE_CONTROL_CLIENT
,
Constant Field Valuespublic static final String EXTRA_REMOTE_CONTROL_CLIENT_GENERATION
#REMOTE_CONTROL_CLIENT_CHANGED_ACTION
,
Constant Field Valuespublic static final String EXTRA_REMOTE_CONTROL_CLIENT_NAME
#REMOTE_CONTROL_CLIENT_CHANGED_ACTION
,
Constant Field Valuespublic static final String EXTRA_REMOTE_CONTROL_EVENT_RECEIVER
#REMOTE_CONTROL_CLIENT_CHANGED_ACTION
,
Constant Field Valuespublic static final String EXTRA_REMOTE_CONTROL_CLIENT_INFO_CHANGED
#REMOTE_CONTROL_CLIENT_CHANGED_ACTION
,
Constant Field Valuespublic static final int DEVICE_OUT_EARPIECE
DEVICE_OUT_WIRED_HEADPHONE
.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_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_DEFAULT
getDevicesForStream(int)
, but could be
used in the future in a set method to select whatever default device is chosen by the
platform-specific implementation.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 primary output stream, in decimal Hz.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 primary output stream, in decimal PCM frames.public AudioManager(Context context)
public void preDispatchKeyEvent(KeyEvent event, int stream)
public void handleKeyDown(KeyEvent event, int stream)
public void handleKeyUp(KeyEvent event, int stream)
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.
direction
- The direction to adjust the volume. One of
ADJUST_LOWER
, ADJUST_RAISE
, or
ADJUST_SAME
.flags
- One or more flags.adjustSuggestedStreamVolume(int, int, int)
,
adjustStreamVolume(int, int, int)
,
setStreamVolume(int, int, int)
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.
direction
- The direction to adjust the volume. One of
ADJUST_LOWER
, ADJUST_RAISE
, or
ADJUST_SAME
.suggestedStreamType
- The stream type that will be used if there
isn't a relevant stream. USE_DEFAULT_STREAM_TYPE
is valid here.flags
- One or more flags.adjustVolume(int, int)
,
adjustStreamVolume(int, int, int)
,
setStreamVolume(int, int, int)
public void adjustMasterVolume(int steps, int flags)
steps
- The number of volume steps to adjust. A positive
value will raise the volume.flags
- One or more 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 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 getMasterStreamType()
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.
ringerMode
- The ringer mode, one of RINGER_MODE_NORMAL
,
RINGER_MODE_SILENT
, or RINGER_MODE_VIBRATE
.getRingerMode()
public void setStreamVolume(int streamType, int index, int flags)
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)
public int getMasterMaxVolume()
public int getMasterVolume()
public int getLastAudibleMasterVolume()
public void setMasterVolume(int index, int flags)
index
- The volume index to set. See
#getMasterMaxVolume(int)
for the largest valid value.flags
- One or more flags.#getMasterMaxVolume(int)
,
#getMasterVolume(int)
public void setStreamSolo(int streamType, boolean state)
The solo command is protected against client process death: if a process with an active solo request on a stream dies, all streams that were muted because of this request will be unmuted automatically.
The solo requests for a given stream are cumulative: the AudioManager can receive several solo requests from one or more clients and the stream will be unsoloed only when the same number of unsolo requests are received.
For a better user experience, applications MUST unsolo a soloed stream in onPause() and solo is again in onResume() if appropriate.
streamType
- The stream to be soloed/unsoloed.state
- The required solo state: true for solo ON, false for solo OFFpublic void setStreamMute(int streamType, boolean state)
The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically.
The mute requests for a given stream are cumulative: the AudioManager can receive several mute requests from one or more clients and the stream will be unmuted only when the same number of unmute requests are received.
For a better user experience, applications MUST unmute a muted stream in onPause() and mute is again in onResume() if appropriate.
This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.
streamType
- The stream to be muted/unmuted.state
- The required mute state: true for mute ON, false for mute OFFpublic boolean isStreamMute(int streamType)
public void setMasterMute(boolean state)
public void setMasterMute(boolean state, int flags)
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.
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()
public void setRemoteSubmixOn(boolean on, int address)
@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 isSpeechRecognitionActive()
MediaRecorder.AudioSource.VOICE_RECOGNITION
is underway.public void adjustLocalOrRemoteStreamVolume(int streamType, int direction)
@Deprecated public void setParameter(String key, String value)
#setPrameters(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
,
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
,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.
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 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 void registerMediaButtonEventReceiver(ComponentName eventReceiver)
eventReceiver
- identifier of a BroadcastReceiver
that will receive the media button intent. This broadcast receiver must be declared
in the application manifest. The package of the component must match that of
the context you're registering from.public void registerMediaButtonIntent(PendingIntent pi, ComponentName eventReceiver)
public void registerMediaButtonEventReceiverForCalls(ComponentName eventReceiver)
eventReceiver
- the component that will receive the media button key events,
no-op if eventReceiver is nullpublic void unregisterMediaButtonEventReceiverForCalls()
public void unregisterMediaButtonEventReceiver(ComponentName eventReceiver)
eventReceiver
- identifier of a BroadcastReceiver
that was registered with registerMediaButtonEventReceiver(ComponentName)
.public void unregisterMediaButtonIntent(PendingIntent pi, ComponentName eventReceiver)
public void registerRemoteControlClient(RemoteControlClient rcClient)
rcClient
- The remote control client from which remote controls will receive
information to display.RemoteControlClient
public void unregisterRemoteControlClient(RemoteControlClient rcClient)
rcClient
- The remote control client to unregister.registerRemoteControlClient(RemoteControlClient)
public void registerRemoteControlDisplay(IRemoteControlDisplay rcd)
rcd
- public void unregisterRemoteControlDisplay(IRemoteControlDisplay rcd)
rcd
- public void remoteControlDisplayUsesBitmapSize(IRemoteControlDisplay rcd, int w, int h)
rcd
- w
- the maximum width of the expected bitmap. Negative values indicate it is
useless to send artwork.h
- the maximum height of the expected bitmap. Negative values indicate it is
useless to send artwork.public void reloadAudioSettings()
public boolean isSilentMode()
getRingerMode()
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_AUX_DIGITAL
,
DEVICE_OUT_ANLG_DOCK_HEADSET
,
DEVICE_OUT_DGTL_DOCK_HEADSET
.
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 device, int state, 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)
device
- Bluetooth device connected/disconnectedstate
- new connection state (BluetoothProfile.STATE_xxx)public IRingtonePlayer getRingtonePlayer()
public String getProperty(String key)
key
- One of the strings corresponding to a property key: either
PROPERTY_OUTPUT_SAMPLE_RATE
or
PROPERTY_OUTPUT_FRAMES_PER_BUFFER