AudioCapabilitiesReceiver

@UnstableApi
public final class AudioCapabilitiesReceiver


Receives broadcast events indicating changes to the device's audio capabilities, notifying a Listener when audio capability changes occur.

Summary

Nested types

Listener notified when audio capabilities change.

Public constructors

This method is deprecated.

Use AudioCapabilitiesReceiver instead.

AudioCapabilitiesReceiver(
    Context context,
    AudioCapabilitiesReceiver.Listener listener,
    AudioAttributes audioAttributes,
    @Nullable AudioDeviceInfo routedDevice
)

Public methods

AudioCapabilities

Registers the receiver, meaning it will notify the listener when audio capability changes occur.

void

Updates the AudioAttributes used by this instance.

void
@RequiresApi(value = 23)
setRoutedDevice(@Nullable AudioDeviceInfo routedDevice)

Updates the AudioDeviceInfo audio will be routed to.

void

Unregisters the receiver, meaning it will no longer notify the listener when audio capability changes occur.

Public constructors

AudioCapabilitiesReceiver

public AudioCapabilitiesReceiver(
    Context context,
    AudioCapabilitiesReceiver.Listener listener
)

AudioCapabilitiesReceiver

public AudioCapabilitiesReceiver(
    Context context,
    AudioCapabilitiesReceiver.Listener listener,
    AudioAttributes audioAttributes,
    @Nullable AudioDeviceInfo routedDevice
)
Parameters
Context context

A context for registering the receiver.

AudioCapabilitiesReceiver.Listener listener

The listener to notify when audio capabilities change.

AudioAttributes audioAttributes

The AudioAttributes.

@Nullable AudioDeviceInfo routedDevice

The AudioDeviceInfo audio will be routed to if known, or null to assume the default route.

Public methods

register

public AudioCapabilities register()

Registers the receiver, meaning it will notify the listener when audio capability changes occur. The current audio capabilities will be returned. It is important to call unregister when the receiver is no longer required.

Returns
AudioCapabilities

The current audio capabilities for the device.

setAudioAttributes

public void setAudioAttributes(AudioAttributes audioAttributes)

Updates the AudioAttributes used by this instance.

Parameters
AudioAttributes audioAttributes

The AudioAttributes.

setRoutedDevice

@RequiresApi(value = 23)
public void setRoutedDevice(@Nullable AudioDeviceInfo routedDevice)

Updates the AudioDeviceInfo audio will be routed to.

Parameters
@Nullable AudioDeviceInfo routedDevice

The AudioDeviceInfo audio will be routed to if known, or null to assume the default route.

unregister

public void unregister()

Unregisters the receiver, meaning it will no longer notify the listener when audio capability changes occur.