# AudioManagerCompat

Artifact: [androidx.media:media](https://developer.android.com/jetpack/androidx/releases/media) [View Source](https://cs.android.com/search?q=file:androidx/media/AudioManagerCompat.java+class:androidx.media.AudioManagerCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

*** ** * ** ***


```
class AudioManagerCompat
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> androidx.media is deprecated. Please migrate to [androidx.media3](https://developer.android.com/media/media3).

Compatibility library for `https://developer.android.com/reference/android/media/AudioManager.html` with fallbacks for older platforms.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#AUDIOFOCUS_GAIN() = 1` **This property is deprecated.** Deprecated in Java |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#AUDIOFOCUS_GAIN_TRANSIENT() = 2` **This property is deprecated.** Deprecated in Java |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE() = 4` **This property is deprecated.** Deprecated in Java |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK() = 3` **This property is deprecated.** Deprecated in Java |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `[abandonAudioFocusRequest](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#abandonAudioFocusRequest(android.media.AudioManager,androidx.media.AudioFocusRequestCompat))( audioManager: https://developer.android.com/reference/android/media/AudioManager.html, focusRequest: https://developer.android.com/reference/kotlin/androidx/media/AudioFocusRequestCompat )` **This function is deprecated.** Deprecated in Java |
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `[getStreamMaxVolume](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#getStreamMaxVolume(android.media.AudioManager,int))(audioManager: https://developer.android.com/reference/android/media/AudioManager.html, streamType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `[getStreamMinVolume](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#getStreamMinVolume(android.media.AudioManager,int))(audioManager: https://developer.android.com/reference/android/media/AudioManager.html, streamType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `[isVolumeFixed](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#isVolumeFixed(android.media.AudioManager))(audioManager: https://developer.android.com/reference/android/media/AudioManager.html)` **This function is deprecated.** Deprecated in Java |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `[requestAudioFocus](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#requestAudioFocus(android.media.AudioManager,androidx.media.AudioFocusRequestCompat))( audioManager: https://developer.android.com/reference/android/media/AudioManager.html, focusRequest: https://developer.android.com/reference/kotlin/androidx/media/AudioFocusRequestCompat )` **This function is deprecated.** Deprecated in Java |

## Constants

### AUDIOFOCUS_GAIN

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
const val AUDIOFOCUS_GAIN = 1: Int
```

> [!CAUTION]
> **This property is deprecated.**   
> Deprecated in Java

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

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html#onAudioFocusChange(int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#requestAudioFocus(android.media.AudioManager,androidx.media.AudioFocusRequestCompat)` |   |

### AUDIOFOCUS_GAIN_TRANSIENT

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
const val AUDIOFOCUS_GAIN_TRANSIENT = 2: Int
```

> [!CAUTION]
> **This property is deprecated.**   
> Deprecated in Java

Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time. Examples of temporary changes are the playback of driving directions, or an event notification.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html#onAudioFocusChange(int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#requestAudioFocus(android.media.AudioManager,androidx.media.AudioFocusRequestCompat)` |   |

### AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
const val AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE = 4: Int
```

> [!CAUTION]
> **This property is deprecated.**   
> Deprecated in Java

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#requestAudioFocus(android.media.AudioManager,androidx.media.AudioFocusRequestCompat)` |   |

### AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
const val AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK = 3: Int
```

> [!CAUTION]
> **This property is deprecated.**   
> Deprecated in Java

Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, and where it is acceptable for other audio applications to keep playing after having lowered their output level (also referred to as "ducking"). Examples of temporary changes are the playback of driving directions where playback of music in the background is acceptable.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html#onAudioFocusChange(int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#requestAudioFocus(android.media.AudioManager,androidx.media.AudioFocusRequestCompat)` |   |

## Public functions

### abandonAudioFocusRequest

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
java-static fun [abandonAudioFocusRequest](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#abandonAudioFocusRequest(android.media.AudioManager,androidx.media.AudioFocusRequestCompat))(
    audioManager: AudioManager,
    focusRequest: AudioFocusRequestCompat
): Int
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

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

| Parameters |
|---|---|
| `focusRequest: https://developer.android.com/reference/kotlin/androidx/media/AudioFocusRequestCompat` | the `https://developer.android.com/reference/kotlin/androidx/media/AudioFocusRequestCompat` that was used when requesting focus with `https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#requestAudioFocus(android.media.AudioManager,androidx.media.AudioFocusRequestCompat)`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/media/AudioManager.html#AUDIOFOCUS_REQUEST_FAILED` or `https://developer.android.com/reference/android/media/AudioManager.html#AUDIOFOCUS_REQUEST_GRANTED` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if passed a null argument |

### getStreamMaxVolume

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/media#1.2.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
java-static fun [getStreamMaxVolume](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#getStreamMaxVolume(android.media.AudioManager,int))(audioManager: AudioManager, streamType: Int): @IntRange(from = 0) Int
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Returns the maximum volume index for a particular stream.

| Parameters |
|---|---|
| `streamType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The stream type whose maximum volume index is returned. Value is one of the following: - `AudioManager.STREAM_VOICE_CALL` - `AudioManager.STREAM_SYSTEM` - `AudioManager.STREAM_RING` - `AudioManager.STREAM_MUSIC` - `AudioManager.STREAM_ALARM` - `AudioManager.STREAM_NOTIFICATION` - `AudioManager.STREAM_DTMF` - `AudioManager.STREAM_ACCESSIBILITY` <br /> |

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The maximum valid volume index for the stream. |

### getStreamMinVolume

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/media#1.2.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
java-static fun [getStreamMinVolume](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#getStreamMinVolume(android.media.AudioManager,int))(audioManager: AudioManager, streamType: Int): @IntRange(from = 0) Int
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Returns the minimum volume index for a particular stream.

| Parameters |
|---|---|
| `streamType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The stream type whose minimum volume index is returned. Value is one of the following: - `AudioManager.STREAM_VOICE_CALL` - `AudioManager.STREAM_SYSTEM` - `AudioManager.STREAM_RING` - `AudioManager.STREAM_MUSIC` - `AudioManager.STREAM_ALARM` - `AudioManager.STREAM_NOTIFICATION` - `AudioManager.STREAM_DTMF` - `AudioManager.STREAM_ACCESSIBILITY` <br /> |

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The minimum valid volume index for the stream. |

### isVolumeFixed

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/media#1.5.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
java-static fun [isVolumeFixed](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#isVolumeFixed(android.media.AudioManager))(audioManager: AudioManager): Boolean
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Indicates if the device implements a fixed volume policy.

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

Compatibility: It returns `false` on API level below 21 even if the device has fixed volume.

### requestAudioFocus

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
java-static fun [requestAudioFocus](https://developer.android.com/reference/kotlin/androidx/media/AudioManagerCompat#requestAudioFocus(android.media.AudioManager,androidx.media.AudioFocusRequestCompat))(
    audioManager: AudioManager,
    focusRequest: AudioFocusRequestCompat
): Int
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Requests audio focus. See the `https://developer.android.com/reference/kotlin/androidx/media/AudioFocusRequestCompat` for information about the options available to configure your request, and notification of focus gain and loss.

| Parameters |
|---|---|
| `focusRequest: https://developer.android.com/reference/kotlin/androidx/media/AudioFocusRequestCompat` | an `https://developer.android.com/reference/kotlin/androidx/media/AudioFocusRequestCompat` instance used to configure how focus is requested. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/media/AudioManager.html#AUDIOFOCUS_REQUEST_FAILED` or `https://developer.android.com/reference/android/media/AudioManager.html#AUDIOFOCUS_REQUEST_GRANTED`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if passed a null argument |