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
void finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
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

Added in 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

Added in 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

Added in 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

Added in 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 void finalize ()

Added in API level 11

Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

public List<BluetoothDevice> getConnectedDevices ()

Added in 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)

Added in 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)

Added in 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)

Added in API level 11

Check if A2DP profile is streaming music.

Requires BLUETOOTH permission.

Parameters
device BluetoothDevice device