IT. Expert System.

Android Reference

AudioManager


android.media

Class AudioManager



  • public class AudioManager
    extends Object
    AudioManager provides access to volume and ringer mode control.

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

    • Constructor Detail

      • AudioManager

        public AudioManager(Context context)
    • Method Detail

      • preDispatchKeyEvent

        public void preDispatchKeyEvent(KeyEvent event,
                               int stream)
      • handleKeyDown

        public void handleKeyDown(KeyEvent event,
                         int stream)
      • handleKeyUp

        public void handleKeyUp(KeyEvent event,
                       int stream)
      • adjustVolume

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

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

        Parameters:
        direction - The direction to adjust the volume. One of ADJUST_LOWER, ADJUST_RAISE, or ADJUST_SAME.
        flags - One or more flags.
        See Also:
        adjustSuggestedStreamVolume(int, int, int), adjustStreamVolume(int, int, int), setStreamVolume(int, int, int)
      • adjustMasterVolume

        public void adjustMasterVolume(int steps,
                              int flags)
        Adjusts the master volume for the device's audio amplifier.

        Parameters:
        steps - The number of volume steps to adjust. A positive value will raise the volume.
        flags - One or more flags.
      • isValidRingerMode

        public static boolean isValidRingerMode(int ringerMode)
        Checks valid ringer mode values.
        Returns:
        true if the ringer mode indicated is valid, false otherwise.
        See Also:
        setRingerMode(int)
      • getStreamMaxVolume

        public int getStreamMaxVolume(int streamType)
        Returns the maximum volume index for a particular stream.
        Parameters:
        streamType - The stream type whose maximum volume index is returned.
        Returns:
        The maximum valid volume index for the stream.
        See Also:
        getStreamVolume(int)
      • getStreamVolume

        public int getStreamVolume(int streamType)
        Returns the current volume index for a particular stream.
        Parameters:
        streamType - The stream type whose volume index is returned.
        Returns:
        The current volume index for the stream.
        See Also:
        getStreamMaxVolume(int), setStreamVolume(int, int, int)
      • getLastAudibleStreamVolume

        public int getLastAudibleStreamVolume(int streamType)
        Get last audible volume before stream was muted.
      • getMasterStreamType

        public int getMasterStreamType()
        Get the stream type whose volume is driving the UI sounds volume. UI sounds are screen lock/unlock, camera shutter, key clicks...
      • setRingerMode

        public void setRingerMode(int ringerMode)
        Sets the ringer mode.

        Silent mode will mute the volume and will not vibrate. Vibrate mode will mute the volume and vibrate. Normal mode will be audible and may vibrate according to user settings.

        Parameters:
        ringerMode - The ringer mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE.
        See Also:
        getRingerMode()
      • setStreamVolume

        public void setStreamVolume(int streamType,
                           int index,
                           int flags)
        Sets the volume index for a particular stream.
        Parameters:
        streamType - The stream whose volume index should be set.
        index - The volume index to set. See getStreamMaxVolume(int) for the largest valid value.
        flags - One or more flags.
        See Also:
        getStreamMaxVolume(int), getStreamVolume(int)
      • getMasterMaxVolume

        public int getMasterMaxVolume()
        Returns the maximum volume index for master volume.
      • getMasterVolume

        public int getMasterVolume()
        Returns the current volume index for master volume.
        Returns:
        The current volume index for master volume.
      • getLastAudibleMasterVolume

        public int getLastAudibleMasterVolume()
        Get last audible volume before master volume was muted.
      • setMasterVolume

        public void setMasterVolume(int index,
                           int flags)
        Sets the volume index for master volume.
        Parameters:
        index - The volume index to set. See #getMasterMaxVolume(int) for the largest valid value.
        flags - One or more flags.
        See Also:
        #getMasterMaxVolume(int), #getMasterVolume(int)
      • setStreamSolo

        public void setStreamSolo(int streamType,
                         boolean state)
        Solo or unsolo a particular stream. All other streams are muted.

        The solo command is protected against client process death: if a process with an active solo request on a stream dies, all streams that were muted because of this request will be unmuted automatically.

        The solo requests for a given stream are cumulative: the AudioManager can receive several solo requests from one or more clients and the stream will be unsoloed only when the same number of unsolo requests are received.

        For a better user experience, applications MUST unsolo a soloed stream in onPause() and solo is again in onResume() if appropriate.

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

        public void setStreamMute(int streamType,
                         boolean state)
        Mute or unmute an audio stream.

        The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically.

        The mute requests for a given stream are cumulative: the AudioManager can receive several mute requests from one or more clients and the stream will be unmuted only when the same number of unmute requests are received.

        For a better user experience, applications MUST unmute a muted stream in onPause() and mute is again in onResume() if appropriate.

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

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

        public boolean isStreamMute(int streamType)
        get stream mute state.
      • setMasterMute

        public void setMasterMute(boolean state)
        set master mute state.
      • setMasterMute

        public void setMasterMute(boolean state,
                         int flags)
        set master mute state with optional flags.
      • isMasterMute

        public boolean isMasterMute()
        get master mute state.
      • forceVolumeControlStream

        public void forceVolumeControlStream(int streamType)
        forces the stream controlled by hard volume keys specifying streamType == -1 releases control to the logic.
      • shouldVibrate

        public boolean shouldVibrate(int vibrateType)
        Deprecated. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().
        Returns whether a particular type should vibrate according to user settings and the current ringer mode.

        This shouldn't be needed by most clients that use notifications to vibrate. The notification manager will not vibrate if the policy doesn't allow it, so the client should always set a vibrate pattern and let the notification manager control whether or not to actually vibrate.

        Parameters:
        vibrateType - The type of vibrate. One of VIBRATE_TYPE_NOTIFICATION or VIBRATE_TYPE_RINGER.
        Returns:
        Whether the type should vibrate at the instant this method is called.
        See Also:
        setVibrateSetting(int, int), getVibrateSetting(int)
      • setSpeakerphoneOn

        public void setSpeakerphoneOn(boolean on)
        Sets the speakerphone on or off.

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

        Parameters:
        on - set true to turn on speakerphone; false to turn it off
      • isSpeakerphoneOn

        public boolean isSpeakerphoneOn()
        Checks whether the speakerphone is on or off.
        Returns:
        true if speakerphone is on, false if it's off
      • isBluetoothScoAvailableOffCall

        public boolean isBluetoothScoAvailableOffCall()
        Indicates if current platform supports use of SCO for off call use cases. Application wanted to use bluetooth SCO audio when the phone is not in call must first call this method to make sure that the platform supports this feature.
        Returns:
        true if bluetooth SCO can be used for audio when not in call false otherwise
        See Also:
        startBluetoothSco()
      • startBluetoothSco

        public void startBluetoothSco()
        Start bluetooth SCO audio connection.

        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:

        • the stream type must be STREAM_VOICE_CALL
        • the format must be mono
        • the sampling must be 16kHz or 8kHz

        The following restrictions apply on input streams:

        • the format must be mono
        • the sampling must be 8kHz

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

        See Also:
        stopBluetoothSco(), ACTION_SCO_AUDIO_STATE_UPDATED
      • stopBluetoothSco

        public void stopBluetoothSco()
        Stop bluetooth SCO audio connection.

        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.

        See Also:
        startBluetoothSco()
      • setBluetoothScoOn

        public void setBluetoothScoOn(boolean on)
        Request use of Bluetooth SCO headset for communications.

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

        Parameters:
        on - set true to use bluetooth SCO for communications; false to not use bluetooth SCO for communications
      • isBluetoothScoOn

        public boolean isBluetoothScoOn()
        Checks whether communications use Bluetooth SCO.
        Returns:
        true if SCO is used for communications; false if otherwise
      • setBluetoothA2dpOn

        @Deprecated
        public void setBluetoothA2dpOn(boolean on)
        Deprecated. Do not use.
        Parameters:
        on - set true to route A2DP audio to/from Bluetooth headset; false disable A2DP audio
      • isBluetoothA2dpOn

        public boolean isBluetoothA2dpOn()
        Checks whether A2DP audio routing to the Bluetooth headset is on or off.
        Returns:
        true if A2DP audio is being routed to/from Bluetooth headset; false if otherwise
      • setRemoteSubmixOn

        public void setRemoteSubmixOn(boolean on,
                             int address)
      • setWiredHeadsetOn

        @Deprecated
        public void setWiredHeadsetOn(boolean on)
        Deprecated. Do not use.
        Sets audio routing to the wired headset on or off.
        Parameters:
        on - set true to route audio to/from wired headset; false disable wired headset audio
      • isWiredHeadsetOn

        public boolean isWiredHeadsetOn()
        Deprecated. Use only to check is a headset is connected or not.
        Checks whether a wired headset is connected or not.

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

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

        public void setMicrophoneMute(boolean on)
        Sets the microphone mute on or off.

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

        Parameters:
        on - set true to mute the microphone; false to turn mute off
      • isMicrophoneMute

        public boolean isMicrophoneMute()
        Checks whether the microphone mute is on or off.
        Returns:
        true if microphone is muted, false if it's not
      • setMode

        public void setMode(int mode)
        Sets the audio mode.

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

        Parameters:
        mode - 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.
      • setRouting

        @Deprecated
        public void setRouting(int mode,
                                 int routes,
                                 int mask)
        Deprecated. Do not set audio routing directly, use setSpeakerphoneOn(), setBluetoothScoOn() methods instead.
        Sets the audio routing for a specified mode
        Parameters:
        mode - audio mode to change route. E.g., MODE_RINGTONE.
        routes - bit vector of routes requested, created from one or more of ROUTE_xxx types. Set bits indicate that route should be on
        mask - bit vector of routes to change, created from one or more of ROUTE_xxx types. Unset bits indicate the route should be left unchanged
      • getRouting

        @Deprecated
        public int getRouting(int mode)
        Deprecated. Do not query audio routing directly, use isSpeakerphoneOn(), isBluetoothScoOn(), isBluetoothA2dpOn() and isWiredHeadsetOn() methods instead.
        Returns the current audio routing bit vector for a specified mode.
        Parameters:
        mode - audio mode to get route (e.g., MODE_RINGTONE)
        Returns:
        an audio route bit vector that can be compared with ROUTE_xxx bits
      • isMusicActive

        public boolean isMusicActive()
        Checks whether any music is active.
        Returns:
        true if any music tracks are active.
      • adjustLocalOrRemoteStreamVolume

        public void adjustLocalOrRemoteStreamVolume(int streamType,
                                           int direction)
      • setParameter

        @Deprecated
        public void setParameter(String key,
                                   String value)
        Deprecated. Use #setPrameters(String) instead
      • setParameters

        public void setParameters(String keyValuePairs)
        Sets a variable number of parameter values to audio hardware.
        Parameters:
        keyValuePairs - list of parameters key value pairs in the form: key1=value1;key2=value2;...
      • getParameters

        public String getParameters(String keys)
        Sets a varaible number of parameter values to audio hardware.
        Parameters:
        keys - list of parameters
        Returns:
        list of parameters key value pairs in the form: key1=value1;key2=value2;...
      • loadSoundEffects

        public void loadSoundEffects()
        Load Sound effects. This method must be called when sound effects are enabled.
      • unloadSoundEffects

        public void unloadSoundEffects()
        Unload Sound effects. This method can be called to free some memory when sound effects are disabled.
      • requestAudioFocus

        public int requestAudioFocus(AudioManager.OnAudioFocusChangeListener l,
                            int streamType,
                            int durationHint)
        Request audio focus. Send a request to obtain the audio focus
        Parameters:
        l - the listener to be notified of audio focus changes
        streamType - the main audio stream type affected by the focus request
        durationHint - use AUDIOFOCUS_GAIN_TRANSIENT to indicate this focus request is temporary, and focus will be abandonned shortly. Examples of transient requests are for the playback of driving directions, or notifications sounds. Use AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK to indicate also that it's ok for the previous focus owner to keep playing if it ducks its audio output. Use AUDIOFOCUS_GAIN for a focus request of unknown duration such as the playback of a song or a video.
        Returns:
        AUDIOFOCUS_REQUEST_FAILED or AUDIOFOCUS_REQUEST_GRANTED
      • requestAudioFocusForCall

        public void requestAudioFocusForCall(int streamType,
                                    int durationHint)
        Parameters:
        streamType - use STREAM_RING for focus requests when ringing, VOICE_CALL for the establishment of the call
        durationHint - the type of focus request. AUDIOFOCUS_GAIN_TRANSIENT is recommended so media applications resume after a call
      • abandonAudioFocusForCall

        public void abandonAudioFocusForCall()
      • registerMediaButtonEventReceiver

        public void registerMediaButtonEventReceiver(ComponentName eventReceiver)
        Register a component to be the sole receiver of MEDIA_BUTTON intents.
        Parameters:
        eventReceiver - identifier of a BroadcastReceiver that will receive the media button intent. This broadcast receiver must be declared in the application manifest. The package of the component must match that of the context you're registering from.
      • registerMediaButtonEventReceiverForCalls

        public void registerMediaButtonEventReceiverForCalls(ComponentName eventReceiver)
        Parameters:
        eventReceiver - the component that will receive the media button key events, no-op if eventReceiver is null
      • unregisterMediaButtonEventReceiverForCalls

        public void unregisterMediaButtonEventReceiverForCalls()
      • registerRemoteControlClient

        public void registerRemoteControlClient(RemoteControlClient rcClient)
        Registers the remote control client for providing information to display on the remote controls.
        Parameters:
        rcClient - The remote control client from which remote controls will receive information to display.
        See Also:
        RemoteControlClient
      • registerRemoteControlDisplay

        public void registerRemoteControlDisplay(IRemoteControlDisplay rcd)
        Parameters:
        rcd -
      • unregisterRemoteControlDisplay

        public void unregisterRemoteControlDisplay(IRemoteControlDisplay rcd)
        Parameters:
        rcd -
      • remoteControlDisplayUsesBitmapSize

        public void remoteControlDisplayUsesBitmapSize(IRemoteControlDisplay rcd,
                                              int w,
                                              int h)
        Parameters:
        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.
      • reloadAudioSettings

        public void reloadAudioSettings()
      • isSilentMode

        public boolean isSilentMode()
        Checks whether the phone is in silent mode, with or without vibrate.
        Returns:
        true if phone is in silent mode, with or without vibrate.
        See Also:
        getRingerMode()
      • setWiredDeviceConnectionState

        public void setWiredDeviceConnectionState(int device,
                                         int state,
                                         String name)
        Indicate wired accessory connection state change.
        Parameters:
        device - type of device connected/disconnected (AudioManager.DEVICE_OUT_xxx)
        state - new connection state: 1 connected, 0 disconnected
        name - device name
      • setBluetoothA2dpDeviceConnectionState

        public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device,
                                                int state)
        Indicate A2DP sink connection state change.
        Parameters:
        device - Bluetooth device connected/disconnected
        state - new connection state (BluetoothProfile.STATE_xxx)
        Returns:
        a delay in ms that the caller should wait before broadcasting BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED intent.
      • getRingtonePlayer

        public IRingtonePlayer getRingtonePlayer()
      • getProperty

        public String getProperty(String key)
        Returns the value of the property with the specified key.
        Parameters:
        key - One of the strings corresponding to a property key: either PROPERTY_OUTPUT_SAMPLE_RATE or PROPERTY_OUTPUT_FRAMES_PER_BUFFER
        Returns:
        A string representing the associated value for that property key, or null if there is no value for that key.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1719 / 96487518. Delta: 0.08603 с