# VolumeProviderCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-media-compat:28.0.0-alpha1  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v4-media/VolumeProviderCompat#nestedclasses)\|[Constants](https://developer.android.com/reference/android/support/v4-media/VolumeProviderCompat#constants)\|[Ctors](https://developer.android.com/reference/android/support/v4-media/VolumeProviderCompat#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v4-media/VolumeProviderCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4-media/VolumeProviderCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4-media/VolumeProviderCompat#)  

# VolumeProviderCompat

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


abstract
class
VolumeProviderCompat
`  
`

extends Object


``


`

|---|-----------------------------------------------|
| java.lang.Object                                 ||
| ↳ | android.support.v4.media.VolumeProviderCompat |

<br />

*** ** * ** ***

Handles requests to adjust or set the volume on a session. This is also used to push volume updates back to the session after a request has been handled. You can set a volume provider on a session by calling[setPlaybackToRemote(VolumeProviderCompat)](https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#setPlaybackToRemote(android.support.v4.media.VolumeProviderCompat)).

## Summary

|                                                                              ### Nested classes                                                                              ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class` | [VolumeProviderCompat.Callback](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat.Callback) Listens for changes to the volume. |

|                                                                                                                                                          ### Constants                                                                                                                                                           ||
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [VOLUME_CONTROL_ABSOLUTE](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#VOLUME_CONTROL_ABSOLUTE) The volume control uses an absolute value.                                                                                                                                       |
| `int` | [VOLUME_CONTROL_FIXED](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#VOLUME_CONTROL_FIXED) The volume is fixed and can not be modified.                                                                                                                                           |
| `int` | [VOLUME_CONTROL_RELATIVE](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#VOLUME_CONTROL_RELATIVE) The volume control uses relative adjustment via[onAdjustVolume(int)](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#onAdjustVolume(int)). |

|                                                                                                                         ### Public constructors                                                                                                                          ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[VolumeProviderCompat](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#VolumeProviderCompat(int, int, int))`(int volumeControl, int maxVolume, int currentVolume) ` Create a new volume provider for handling volume events. |

|                                                                                                                                                                                  ### Public methods                                                                                                                                                                                  ||
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` final int`  | ` `[getCurrentVolume](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#getCurrentVolume())`() ` Get the current volume of the provider.                                                                                                                                                                                          |
| ` final int`  | ` `[getMaxVolume](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#getMaxVolume())`() ` Get the maximum volume this provider allows.                                                                                                                                                                                             |
| ` final int`  | ` `[getVolumeControl](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#getVolumeControl())`() ` Get the volume control type that this volume provider uses.                                                                                                                                                                      |
| ` Object`     | ` `[getVolumeProvider](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#getVolumeProvider())`() ` Gets the underlying framework[VolumeProvider](https://developer.android.com/reference/android/media/VolumeProvider.html)object.                                                                                                |
| ` void`       | ` `[onAdjustVolume](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#onAdjustVolume(int))`(int direction) ` Override to handle requests to adjust the volume of the current output.                                                                                                                                              |
| ` void`       | ` `[onSetVolumeTo](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#onSetVolumeTo(int))`(int volume) ` Override to handle requests to set the volume of the current output.                                                                                                                                                      |
| ` void`       | ` `[setCallback](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#setCallback(android.support.v4.media.VolumeProviderCompat.Callback))`(`[VolumeProviderCompat.Callback](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat.Callback)` callback) ` Sets a callback to receive volume changes. |
| ` final void` | ` `[setCurrentVolume](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#setCurrentVolume(int))`(int currentVolume) ` Set the current volume and notify the system that the volume has been changed.                                                                                                                               |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4-media/VolumeProviderCompat#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Constants

### VOLUME_CONTROL_ABSOLUTE

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int VOLUME_CONTROL_ABSOLUTE
```

The volume control uses an absolute value. It may be adjusted using[onAdjustVolume(int)](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#onAdjustVolume(int))or set directly using[onSetVolumeTo(int)](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#onSetVolumeTo(int)).

<br />

Constant Value: 2 (0x00000002)  

### VOLUME_CONTROL_FIXED

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int VOLUME_CONTROL_FIXED
```

The volume is fixed and can not be modified. Requests to change volume should be ignored.

<br />

Constant Value: 0 (0x00000000)  

### VOLUME_CONTROL_RELATIVE

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int VOLUME_CONTROL_RELATIVE
```

The volume control uses relative adjustment via[onAdjustVolume(int)](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat#onAdjustVolume(int)). Attempts to set the volume to a specific value should be ignored.

<br />

Constant Value: 1 (0x00000001)

## Public constructors

### VolumeProviderCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
VolumeProviderCompat (int volumeControl,
                int maxVolume,
                int currentVolume)
```

Create a new volume provider for handling volume events. You must specify the type of volume control and the maximum volume that can be used.

<br />

|                                           Parameters                                            ||
|-----------------|--------------------------------------------------------------------------------|
| `volumeControl` | `int`: The method for controlling volume that is used by this provider. <br /> |
| `maxVolume`     | `int`: The maximum allowed volume. <br />                                      |
| `currentVolume` | `int`: The current volume. <br />                                              |

## Public methods

### getCurrentVolume

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getCurrentVolume ()
```

Get the current volume of the provider.

<br />

|              Returns              ||
|-------|----------------------------|
| `int` | The current volume. <br /> |

### getMaxVolume

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getMaxVolume ()
```

Get the maximum volume this provider allows.

<br />

|                Returns                ||
|-------|--------------------------------|
| `int` | The max allowed volume. <br /> |

### getVolumeControl

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getVolumeControl ()
```

Get the volume control type that this volume provider uses.

<br />

|                            Returns                             ||
|-------|---------------------------------------------------------|
| `int` | The volume control type for this volume provider <br /> |

### getVolumeProvider

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Object getVolumeProvider ()
```

Gets the underlying framework[VolumeProvider](https://developer.android.com/reference/android/media/VolumeProvider.html)object.

This method is only supported on API 21+.

<br />

<br />

|                                                                      Returns                                                                      ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `Object` | An equivalent[VolumeProvider](https://developer.android.com/reference/android/media/VolumeProvider.html)object, or null if none. <br /> |

### onAdjustVolume

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onAdjustVolume (int direction)
```

Override to handle requests to adjust the volume of the current output.

<br />

|                            Parameters                             ||
|-------------|------------------------------------------------------|
| `direction` | `int`: The direction to adjust the volume in. <br /> |

### onSetVolumeTo

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onSetVolumeTo (int volume)
```

Override to handle requests to set the volume of the current output.

<br />

|                        Parameters                        ||
|----------|------------------------------------------------|
| `volume` | `int`: The volume to set the output to. <br /> |

### setCallback

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setCallback (VolumeProviderCompat.Callback callback)
```

Sets a callback to receive volume changes.

Used internally by the support library.

<br />

<br />

|                     Parameters                     ||
|------------|----------------------------------------|
| `callback` | `VolumeProviderCompat.Callback` <br /> |

### setCurrentVolume

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setCurrentVolume (int currentVolume)
```

Set the current volume and notify the system that the volume has been changed.

<br />

|                            Parameters                            ||
|-----------------|-------------------------------------------------|
| `currentVolume` | `int`: The current volume of the output. <br /> |

-

  ## Classes

  - [AudioAttributesCompat](https://developer.android.com/reference/android/support/v4/media/AudioAttributesCompat)
  - [AudioAttributesCompat.Builder](https://developer.android.com/reference/android/support/v4/media/AudioAttributesCompat.Builder)
  - [MediaBrowserCompat](https://developer.android.com/reference/android/support/v4/media/MediaBrowserCompat)
  - [MediaBrowserCompat.ConnectionCallback](https://developer.android.com/reference/android/support/v4/media/MediaBrowserCompat.ConnectionCallback)
  - [MediaBrowserCompat.CustomActionCallback](https://developer.android.com/reference/android/support/v4/media/MediaBrowserCompat.CustomActionCallback)
  - [MediaBrowserCompat.ItemCallback](https://developer.android.com/reference/android/support/v4/media/MediaBrowserCompat.ItemCallback)
  - [MediaBrowserCompat.MediaItem](https://developer.android.com/reference/android/support/v4/media/MediaBrowserCompat.MediaItem)
  - [MediaBrowserCompat.SearchCallback](https://developer.android.com/reference/android/support/v4/media/MediaBrowserCompat.SearchCallback)
  - [MediaBrowserCompat.SubscriptionCallback](https://developer.android.com/reference/android/support/v4/media/MediaBrowserCompat.SubscriptionCallback)
  - [MediaBrowserServiceCompat](https://developer.android.com/reference/android/support/v4/media/MediaBrowserServiceCompat)
  - [MediaBrowserServiceCompat.BrowserRoot](https://developer.android.com/reference/android/support/v4/media/MediaBrowserServiceCompat.BrowserRoot)
  - [MediaBrowserServiceCompat.Result](https://developer.android.com/reference/android/support/v4/media/MediaBrowserServiceCompat.Result)
  - [MediaDescriptionCompat](https://developer.android.com/reference/android/support/v4/media/MediaDescriptionCompat)
  - [MediaDescriptionCompat.Builder](https://developer.android.com/reference/android/support/v4/media/MediaDescriptionCompat.Builder)
  - [MediaMetadataCompat](https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat)
  - [MediaMetadataCompat.Builder](https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat.Builder)
  - [RatingCompat](https://developer.android.com/reference/android/support/v4/media/RatingCompat)
  - [VolumeProviderCompat](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat)
  - [VolumeProviderCompat.Callback](https://developer.android.com/reference/android/support/v4/media/VolumeProviderCompat.Callback)