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 |
finalize() |
MutableList<BluetoothDevice!>! |
Get connected devices for this specific profile. |
Int |
getConnectionState(device: BluetoothDevice!) Get the current connection state of the profile |
MutableList<BluetoothDevice!>! |
getDevicesMatchingConnectionStates(states: IntArray!) 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 |
isA2dpPlaying(device: BluetoothDevice!) Check if A2DP profile is streaming music. |
Constants
ACTION_CONNECTION_STATE_CHANGED
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
- The current state of the profile.EXTRA_PREVIOUS_STATE
- The previous state of the profile.BluetoothDevice#EXTRA_DEVICE
- The remote device.
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
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
- The current state of the profile.EXTRA_PREVIOUS_STATE
- The previous state of the profile.BluetoothDevice#EXTRA_DEVICE
- The remote device.
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
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
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
fun finalize(): Unit
Exceptions | |
---|---|
java.lang.Throwable |
the Exception raised by this method |
getConnectedDevices
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
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. |
getDevicesMatchingConnectionStates
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
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
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 |