Skip to content

Most visited

Recently visited

navigation
Added in API level 11

BluetoothA2dp

public final class BluetoothA2dp
extends Object implements BluetoothProfile

java.lang.Object
   ↳ 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 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.

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.

Inherited methods

From class java.lang.Object
From interface android.bluetooth.BluetoothProfile

Constants

ACTION_CONNECTION_STATE_CHANGED

Added in API level 11
String ACTION_CONNECTION_STATE_CHANGED

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"

ACTION_PLAYING_STATE_CHANGED

Added in API level 11
String ACTION_PLAYING_STATE_CHANGED

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"

STATE_NOT_PLAYING

Added in API level 11
int STATE_NOT_PLAYING

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)

STATE_PLAYING

Added in API level 11
int STATE_PLAYING

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

finalize

Added in API level 11
void finalize ()

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.

getConnectedDevices

Added in API level 11
List<BluetoothDevice> getConnectedDevices ()

Get connected devices for this specific profile.

Return the set of devices which are in state STATE_CONNECTED

Requires BLUETOOTH permission.

Returns
List<BluetoothDevice> List of devices. The list will be empty on error.

getConnectionState

Added in API level 11
int getConnectionState (BluetoothDevice device)

Get the current connection state of the profile

Requires BLUETOOTH permission.

Parameters
device BluetoothDevice: Remote bluetooth device.
Returns
int State of the profile connection. One of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING

getDevicesMatchingConnectionStates

Added in API level 11
List<BluetoothDevice> getDevicesMatchingConnectionStates (int[] states)

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 int: Array of states. States can be one of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING,
Returns
List<BluetoothDevice> List of devices. The list will be empty on error.

isA2dpPlaying

Added in API level 11
boolean isA2dpPlaying (BluetoothDevice device)

Check if A2DP profile is streaming music.

Requires BLUETOOTH permission.

Parameters
device BluetoothDevice: BluetoothDevice device
Returns
boolean
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.