public final class BluetoothA2dpSink extends Object implements BluetoothProfile
BluetoothA2dpSink is a proxy object for controlling the Bluetooth A2DP Sink
Service via IPC. Use BluetoothAdapter.getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int)
to get
the BluetoothA2dpSink proxy object.
BluetoothProfile.ServiceListener
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_AUDIO_CONFIG_CHANGED
Intent used to broadcast the change in the Playing state of the A2DP Sink
profile.
|
static String |
ACTION_CONNECTION_STATE_CHANGED
Intent used to broadcast the change in connection state of the A2DP Sink
profile.
|
static String |
ACTION_PLAYING_STATE_CHANGED
Intent used to broadcast the change in the Playing state of the A2DP Sink
profile.
|
static String |
EXTRA_AUDIO_CONFIG
Extra for the
ACTION_AUDIO_CONFIG_CHANGED intent. |
static int |
STATE_NOT_PLAYING
A2DP sink device is NOT streaming music.
|
static int |
STATE_PLAYING
A2DP sink device is streaming music.
|
A2DP, A2DP_SINK, AVRCP_CONTROLLER, EXTRA_PREVIOUS_STATE, EXTRA_STATE, GATT, GATT_SERVER, HEADSET, HEADSET_CLIENT, HEALTH, INPUT_DEVICE, MAP, PAN, PBAP, PBAP_CLIENT, PRIORITY_AUTO_CONNECT, PRIORITY_OFF, PRIORITY_ON, PRIORITY_UNDEFINED, SAP, STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING
Modifier and Type | Method and Description |
---|---|
boolean |
connect(BluetoothDevice device)
Initiate connection to a profile of the remote bluetooth device.
|
boolean |
disconnect(BluetoothDevice device)
Initiate disconnection from a profile
This API will return false in scenarios like the profile on the
Bluetooth device is not in connected state etc.
|
void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
BluetoothAudioConfig |
getAudioConfig(BluetoothDevice device)
Get the current audio configuration for the A2DP source device,
or null if the device has no audio configuration
Requires
android.Manifest.permission#BLUETOOTH permission. |
List<BluetoothDevice> |
getConnectedDevices()
Get connected devices for this specific profile.
|
int |
getConnectionState(BluetoothDevice device)
Get the current connection state of the profile
Requires
android.Manifest.permission#BLUETOOTH permission. |
List<BluetoothDevice> |
getDevicesMatchingConnectionStates(int[] states)
Get a list of devices that match any of the given connection
states.
|
int |
getPriority(BluetoothDevice device)
Get the priority of the profile.
|
boolean |
isA2dpPlaying(BluetoothDevice device)
Check if A2DP profile is streaming music.
|
boolean |
setPriority(BluetoothDevice device,
int priority)
Set priority of the profile
The device should already be paired.
|
static String |
stateToString(int state)
Helper for converting a state to a string.
|
public static final String ACTION_CONNECTION_STATE_CHANGED
This intent will have 3 extras:
BluetoothProfile.EXTRA_STATE
- The current state of the profile. BluetoothProfile.EXTRA_PREVIOUS_STATE
- The previous state of the profile.BluetoothDevice.EXTRA_DEVICE
- The remote device. BluetoothProfile.EXTRA_STATE
or BluetoothProfile.EXTRA_PREVIOUS_STATE
can be any of
BluetoothProfile.STATE_DISCONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_DISCONNECTING
.
Requires android.Manifest.permission#BLUETOOTH
permission to
receive.
public static final String ACTION_PLAYING_STATE_CHANGED
This intent will have 3 extras:
BluetoothProfile.EXTRA_STATE
- The current state of the profile. BluetoothProfile.EXTRA_PREVIOUS_STATE
- The previous state of the profile. BluetoothDevice.EXTRA_DEVICE
- The remote device. BluetoothProfile.EXTRA_STATE
or BluetoothProfile.EXTRA_PREVIOUS_STATE
can be any of
STATE_PLAYING
, STATE_NOT_PLAYING
,
Requires android.Manifest.permission#BLUETOOTH
permission to
receive.
public static final int STATE_PLAYING
BluetoothProfile.EXTRA_STATE
or BluetoothProfile.EXTRA_PREVIOUS_STATE
of
ACTION_PLAYING_STATE_CHANGED
intent.public static final int STATE_NOT_PLAYING
BluetoothProfile.EXTRA_STATE
or BluetoothProfile.EXTRA_PREVIOUS_STATE
of
ACTION_PLAYING_STATE_CHANGED
intent.public static final String ACTION_AUDIO_CONFIG_CHANGED
This intent will have 3 extras:
EXTRA_AUDIO_CONFIG
- The audio configuration for the remote device. BluetoothDevice.EXTRA_DEVICE
- The remote device. Requires android.Manifest.permission#BLUETOOTH
permission to
receive.
public static final String EXTRA_AUDIO_CONFIG
ACTION_AUDIO_CONFIG_CHANGED
intent.
This extra represents the current audio configuration of the A2DP source device.
BluetoothAudioConfig
public void finalize()
Object
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.
public boolean connect(BluetoothDevice device)
Currently, the system supports only 1 connection to the A2DP profile. The API will automatically disconnect connected devices before connecting.
This API returns false in scenarios like the profile on the device is already connected or Bluetooth is not turned on. When this API returns true, it is guaranteed that connection state intent for the profile will be broadcasted with the state. Users can get the connection state of the profile from this intent.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth Devicepublic boolean disconnect(BluetoothDevice device)
This API will return false in scenarios like the profile on the Bluetooth device is not in connected state etc. When this API returns, true, it is guaranteed that the connection state change intent will be broadcasted with the state. Users can get the disconnection state of the profile from this intent.
If the disconnection is initiated by a remote device, the state
will transition from BluetoothProfile.STATE_CONNECTED
to
BluetoothProfile.STATE_DISCONNECTED
. If the disconnect is initiated by the
host (local) device the state will transition from
BluetoothProfile.STATE_CONNECTED
to state BluetoothProfile.STATE_DISCONNECTING
to
state BluetoothProfile.STATE_DISCONNECTED
. The transition to
BluetoothProfile.STATE_DISCONNECTING
can be used to distinguish between the
two scenarios.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Remote Bluetooth Devicepublic List<BluetoothDevice> getConnectedDevices()
Return the set of devices which are in state BluetoothProfile.STATE_CONNECTED
Requires android.Manifest.permission#BLUETOOTH
permission.
getConnectedDevices
in interface BluetoothProfile
public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states)
If none of the devices match any of the given states, an empty list will be returned.
Requires android.Manifest.permission#BLUETOOTH
permission.
getDevicesMatchingConnectionStates
in interface BluetoothProfile
states
- Array of states. States can be one of
BluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_DISCONNECTED
, BluetoothProfile.STATE_DISCONNECTING
,public int getConnectionState(BluetoothDevice device)
Requires android.Manifest.permission#BLUETOOTH
permission.
getConnectionState
in interface BluetoothProfile
device
- Remote bluetooth device.BluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_DISCONNECTED
, BluetoothProfile.STATE_DISCONNECTING
public BluetoothAudioConfig getAudioConfig(BluetoothDevice device)
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- Remote bluetooth device.BluetoothAudioConfig
public boolean setPriority(BluetoothDevice device, int priority)
The device should already be paired.
Priority can be one of BluetoothProfile.PRIORITY_ON
orgetBluetoothManager
BluetoothProfile.PRIORITY_OFF
,
Requires android.Manifest.permission#BLUETOOTH_ADMIN
permission.
device
- Paired bluetooth devicepriority
- public int getPriority(BluetoothDevice device)
The priority can be any of:
BluetoothProfile.PRIORITY_AUTO_CONNECT
, BluetoothProfile.PRIORITY_OFF
,
BluetoothProfile.PRIORITY_ON
, BluetoothProfile.PRIORITY_UNDEFINED
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- Bluetooth devicepublic boolean isA2dpPlaying(BluetoothDevice device)
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- BluetoothDevice devicepublic static String stateToString(int state)