Added in API level 11

BluetoothA2dp


class BluetoothA2dp : BluetoothProfile
kotlin.Any
   ↳ android.bluetooth.BluetoothA2dp

This class provides the public APIs to control the Bluetooth A2DP profile.

BluetoothA2dp is a proxy object for controlling the Bluetooth A2DP Service via IPC. Use android.bluetooth.BluetoothAdapter#getProfileProxy to get the BluetoothA2dp proxy object.

Android only supports one connected Bluetooth A2dp device at a time. Each method is protected with its appropriate permission.

Summary

Constants
static String

Intent used to broadcast the change in connection state of the A2DP profile.

static String

Intent used to broadcast the change in the Playing state of the A2DP profile.

static Int

A2DP sink device is NOT streaming music.

static Int

A2DP sink device is streaming music.

Inherited constants
Public methods
Unit

MutableList<BluetoothDevice!>!

Get connected devices for this specific profile.

Int

Get the current connection state of the profile
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).

MutableList<BluetoothDevice!>!

Get a list of devices that match any of the given connection states.

MutableCollection<BluetoothCodecType!>

Returns the list of source codecs that are supported by the current platform.

Boolean

Check if A2DP profile is streaming music.

Constants

ACTION_CONNECTION_STATE_CHANGED

Added in API level 11
static val ACTION_CONNECTION_STATE_CHANGED: String

Intent used to broadcast the change in connection state of the A2DP profile.

This intent will have 3 extras:

EXTRA_STATE or EXTRA_PREVIOUS_STATE can be any of STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED, STATE_DISCONNECTING.
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Value: "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED"

ACTION_PLAYING_STATE_CHANGED

Added in API level 11
static val ACTION_PLAYING_STATE_CHANGED: String

Intent used to broadcast the change in the Playing state of the A2DP profile.

This intent will have 3 extras:

EXTRA_STATE or EXTRA_PREVIOUS_STATE can be any of STATE_PLAYING, STATE_NOT_PLAYING,
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Value: "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED"

STATE_NOT_PLAYING

Added in API level 11
static val STATE_NOT_PLAYING: Int

A2DP sink device is NOT streaming music. This state can be one of EXTRA_STATE or EXTRA_PREVIOUS_STATE of ACTION_PLAYING_STATE_CHANGED intent.

Value: 11

STATE_PLAYING

Added in API level 11
static val STATE_PLAYING: Int

A2DP sink device is streaming music. This state can be one of EXTRA_STATE or EXTRA_PREVIOUS_STATE of ACTION_PLAYING_STATE_CHANGED intent.

Value: 10

Public methods

finalize

Added in API level 11
fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method

getConnectedDevices

Added in API level 11
fun getConnectedDevices(): MutableList<BluetoothDevice!>!

Get connected devices for this specific profile.

Return the set of devices which are in state STATE_CONNECTED
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
MutableList<BluetoothDevice!>! List of devices. The list will be empty on error.

getConnectionState

Added in API level 11
fun getConnectionState(device: BluetoothDevice!): Int

Get the current connection state of the profile
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
device BluetoothDevice!: Remote bluetooth device.
Return
Int Value is android.bluetooth.BluetoothProfile#STATE_DISCONNECTED, android.bluetooth.BluetoothProfile#STATE_CONNECTING, android.bluetooth.BluetoothProfile#STATE_CONNECTED, or android.bluetooth.BluetoothProfile#STATE_DISCONNECTING

getDevicesMatchingConnectionStates

Added in API level 11
fun getDevicesMatchingConnectionStates(states: IntArray!): MutableList<BluetoothDevice!>!

Get a list of devices that match any of the given connection states.

If none of the devices match any of the given states, an empty list will be returned.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
states IntArray!: Array of states. States can be one of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING,
Return
MutableList<BluetoothDevice!>! List of devices. The list will be empty on error.

getSupportedCodecTypes

Added in API level 35
fun getSupportedCodecTypes(): MutableCollection<BluetoothCodecType!>

Returns the list of source codecs that are supported by the current platform.

The list always includes the mandatory SBC codec, and may include optional proprietary codecs.
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
Requires android.Manifest.permission#BLUETOOTH_PRIVILEGED

Return
MutableCollection<BluetoothCodecType!> list of supported source codec types This value cannot be null.

isA2dpPlaying

Added in API level 11
fun isA2dpPlaying(device: BluetoothDevice!): Boolean

Check if A2DP profile is streaming music.
For apps targeting Build.VERSION_CODES#R or lower, this requires the Manifest.permission#BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES#S or or higher, this requires the Manifest.permission#BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
device BluetoothDevice!: BluetoothDevice device