to top
Android APIs
public final class

BluetoothA2dp

extends Object
implements BluetoothProfile
java.lang.Object
   ↳ android.bluetooth.BluetoothA2dp

Class Overview

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 getProfileProxy(Context, BluetoothProfile.ServiceListener, int) 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
String ACTION_CONNECTION_STATE_CHANGED Intent used to broadcast the change in connection state of the A2DP profile.
String ACTION_PLAYING_STATE_CHANGED Intent used to broadcast the change in the Playing state of the A2DP profile.
int STATE_NOT_PLAYING A2DP sink device is NOT streaming music.
int STATE_PLAYING A2DP sink device is streaming music.
[Expand]
Inherited Constants
From interface android.bluetooth.BluetoothProfile
Public Methods
List<BluetoothDevice> getConnectedDevices()
Get connected devices for this specific profile.
int getConnectionState(BluetoothDevice device)
Get the current connection state of the profile

Requires BLUETOOTH permission.

List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states)
Get a list of devices that match any of the given connection states.
boolean isA2dpPlaying(BluetoothDevice device)
Check if A2DP profile is streaming music.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.bluetooth.BluetoothProfile

Constants

public static final String ACTION_CONNECTION_STATE_CHANGED

Since: API Level 11

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.

Requires BLUETOOTH permission to receive.

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

public static final String ACTION_PLAYING_STATE_CHANGED

Since: API Level 11

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,

Requires BLUETOOTH permission to receive.

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

public static final int STATE_NOT_PLAYING

Since: API Level 11

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.

Constant Value: 11 (0x0000000b)

public static final int STATE_PLAYING

Since: API Level 11

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

Constant Value: 10 (0x0000000a)

Public Methods

public List<BluetoothDevice> getConnectedDevices ()

Since: API Level 11

Get connected devices for this specific profile.

Return the set of devices which are in state STATE_CONNECTED

Requires BLUETOOTH permission.

Returns
  • List of devices. The list will be empty on error.

public int getConnectionState (BluetoothDevice device)

Since: API Level 11

Get the current connection state of the profile

Requires BLUETOOTH permission.

Parameters
device Remote bluetooth device.
Returns

public List<BluetoothDevice> getDevicesMatchingConnectionStates (int[] states)

Since: API Level 11

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.

Requires BLUETOOTH permission.

Parameters
states Array of states. States can be one of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING,
Returns
  • List of devices. The list will be empty on error.

public boolean isA2dpPlaying (BluetoothDevice device)

Since: API Level 11

Check if A2DP profile is streaming music.

Requires BLUETOOTH permission.

Parameters
device BluetoothDevice device