Most visited

Recently visited

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()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

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 ()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

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

Hooray!