public final class BluetoothHeadset extends Object implements BluetoothProfile
BluetoothHeadset is a proxy object for controlling the Bluetooth Headset Service via IPC.
Use BluetoothAdapter.getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int)
to get
the BluetoothHeadset proxy object. Use
BluetoothAdapter.closeProfileProxy(int, android.bluetooth.BluetoothProfile)
to close the service connection.
Android only supports one connected Bluetooth Headset at a time. Each method is protected with its appropriate permission.
BluetoothProfile.ServiceListener
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_AUDIO_STATE_CHANGED
Intent used to broadcast the change in the Audio Connection state of the
A2DP profile.
|
static String |
ACTION_CONNECTION_STATE_CHANGED
Intent used to broadcast the change in connection state of the Headset
profile.
|
static String |
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
Intent used to broadcast that the headset has posted a
vendor-specific event.
|
static int |
AT_CMD_TYPE_ACTION
AT command type ACTION used with
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, AT+CHUP. |
static int |
AT_CMD_TYPE_BASIC
AT command type BASIC used with
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, ATD. |
static int |
AT_CMD_TYPE_READ
AT command type READ used with
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, AT+VGM?. |
static int |
AT_CMD_TYPE_SET
AT command type SET used with
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, AT+VGM= |
static int |
AT_CMD_TYPE_TEST
AT command type TEST used with
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, AT+VGM=?. |
static String |
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS
A Parcelable String array extra field in
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT intents that contains
the arguments to the vendor-specific command. |
static String |
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD
A String extra field in
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
intents that contains the name of the vendor-specific command. |
static String |
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
An int extra field in
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
intents that contains the AT command type of the vendor-specific command. |
static int |
STATE_AUDIO_CONNECTED
Headset state when SCO audio is connected.
|
static int |
STATE_AUDIO_CONNECTING
Headset state when SCO audio is connecting.
|
static int |
STATE_AUDIO_DISCONNECTED
Headset state when SCO audio is not connected.
|
static String |
VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY
The intent category to be used with
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
for the companyId |
A2DP, EXTRA_PREVIOUS_STATE, EXTRA_STATE, HEADSET, HEALTH, INPUT_DEVICE, PAN, PBAP, PRIORITY_AUTO_CONNECT, PRIORITY_OFF, PRIORITY_ON, PRIORITY_UNDEFINED, STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING
Modifier and Type | Method and Description |
---|---|
boolean |
acceptIncomingConnect(BluetoothDevice device)
Accept the incoming connection.
|
void |
clccResponse(int index,
int direction,
int status,
int mode,
boolean mpty,
String number,
int type)
Send Headset of CLCC response
|
boolean |
connect(BluetoothDevice device)
Initiate connection to a profile of the remote bluetooth device.
|
boolean |
connectAudio()
Initiates a connection of headset audio.
|
boolean |
disconnect(BluetoothDevice device)
Initiate disconnection from a profile
|
boolean |
disconnectAudio()
Initiates a disconnection of headset audio.
|
int |
getAudioState(BluetoothDevice device)
Get the current audio state of the Headset.
|
int |
getBatteryUsageHint(BluetoothDevice device)
Get battery usage hint for Bluetooth Headset service.
|
List<BluetoothDevice> |
getConnectedDevices()
Get connected devices for this specific profile.
|
int |
getConnectionState(BluetoothDevice device)
Get the current connection state of the profile
|
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 |
isAudioConnected(BluetoothDevice device)
Check if Bluetooth SCO audio is connected.
|
boolean |
isAudioOn()
Check if Bluetooth SCO audio is connected.
|
static boolean |
isBluetoothVoiceDialingEnabled(Context context)
Indicates if current platform supports voice dialing over bluetooth SCO.
|
void |
phoneStateChanged(int numActive,
int numHeld,
int callState,
String number,
int type)
Notify Headset of phone state change.
|
boolean |
rejectIncomingConnect(BluetoothDevice device)
Reject the incoming connection.
|
void |
roamChanged(boolean roaming)
Notify Headset of phone roam state change.
|
boolean |
setPriority(BluetoothDevice device,
int priority)
Set priority of the profile
|
boolean |
startScoUsingVirtualVoiceCall(BluetoothDevice device)
Initiates a SCO channel connection with the headset (if connected).
|
boolean |
startVoiceRecognition(BluetoothDevice device)
Start Bluetooth voice recognition.
|
boolean |
stopScoUsingVirtualVoiceCall(BluetoothDevice device)
Terminates an ongoing SCO connection and the associated virtual
call.
|
boolean |
stopVoiceRecognition(BluetoothDevice device)
Stop Bluetooth Voice Recognition mode, and shut down the
Bluetooth audio path.
|
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_AUDIO_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_AUDIO_CONNECTED
, STATE_AUDIO_DISCONNECTED
,
Requires android.Manifest.permission#BLUETOOTH
permission
to receive.
public static final String ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
This intent will have 4 extras and 1 category.
BluetoothDevice.EXTRA_DEVICE
- The remote Bluetooth Device
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD
- The vendor
specific command EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
- The AT
command type which can be one of AT_CMD_TYPE_READ
,
AT_CMD_TYPE_TEST
, or AT_CMD_TYPE_SET
,
AT_CMD_TYPE_BASIC
,AT_CMD_TYPE_ACTION
. EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS
- Command
arguments. The category is the Company ID of the vendor defining the
vendor-specific command. BluetoothAssignedNumbers
For example, for Plantronics specific events
Category will be VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY
.55
For example, an AT+XEVENT=foo,3 will get translated into
Requires android.Manifest.permission#BLUETOOTH
permission
to receive.
public static final String EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
intents that contains the name of the vendor-specific command.public static final String EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
intents that contains the AT command type of the vendor-specific command.public static final int AT_CMD_TYPE_READ
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, AT+VGM?. There are no arguments for this command type.public static final int AT_CMD_TYPE_TEST
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, AT+VGM=?. There are no arguments for this command type.public static final int AT_CMD_TYPE_SET
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, AT+VGM=public static final int AT_CMD_TYPE_BASIC
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, ATD. Single character commands and everything following the
character are arguments.public static final int AT_CMD_TYPE_ACTION
EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE
For example, AT+CHUP. There are no arguments for action commands.public static final String EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
intents that contains
the arguments to the vendor-specific command.public static final String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY
ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
for the companyIdpublic static final int STATE_AUDIO_DISCONNECTED
BluetoothProfile.EXTRA_STATE
or BluetoothProfile.EXTRA_PREVIOUS_STATE
of
ACTION_AUDIO_STATE_CHANGED
intent.public static final int STATE_AUDIO_CONNECTING
BluetoothProfile.EXTRA_STATE
or BluetoothProfile.EXTRA_PREVIOUS_STATE
of
ACTION_AUDIO_STATE_CHANGED
intent.public static final int STATE_AUDIO_CONNECTED
BluetoothProfile.EXTRA_STATE
or BluetoothProfile.EXTRA_PREVIOUS_STATE
of
ACTION_AUDIO_STATE_CHANGED
intent.public boolean connect(BluetoothDevice device)
Currently, the system supports only 1 connection to the headset/handsfree 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 boolean setPriority(BluetoothDevice device, int priority)
The device should already be paired.
Priority can be one of BluetoothProfile.PRIORITY_ON
or
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 startVoiceRecognition(BluetoothDevice device)
Users can listen to ACTION_AUDIO_STATE_CHANGED
.
If this function returns true, this intent will be broadcasted with
BluetoothProfile.EXTRA_STATE
set to STATE_AUDIO_CONNECTING
.
BluetoothProfile.EXTRA_STATE
will transition from
STATE_AUDIO_CONNECTING
to STATE_AUDIO_CONNECTED
when
audio connection is established and to STATE_AUDIO_DISCONNECTED
in case of failure to establish the audio connection.
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- Bluetooth headsetpublic boolean stopVoiceRecognition(BluetoothDevice device)
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- Bluetooth headsetpublic boolean isAudioConnected(BluetoothDevice device)
Requires android.Manifest.permission#BLUETOOTH
permission.
device
- Bluetooth headsetpublic int getBatteryUsageHint(BluetoothDevice device)
device
- the bluetooth headset.public static boolean isBluetoothVoiceDialingEnabled(Context context)
public boolean acceptIncomingConnect(BluetoothDevice device)
public boolean rejectIncomingConnect(BluetoothDevice device)
public int getAudioState(BluetoothDevice device)
public boolean isAudioOn()
Requires android.Manifest.permission#BLUETOOTH
permission.
public boolean connectAudio()
public boolean disconnectAudio()
public boolean startScoUsingVirtualVoiceCall(BluetoothDevice device)
device
- Remote Bluetooth Devicepublic boolean stopScoUsingVirtualVoiceCall(BluetoothDevice device)
device
- Remote Bluetooth Devicepublic void phoneStateChanged(int numActive, int numHeld, int callState, String number, int type)
public void roamChanged(boolean roaming)
public void clccResponse(int index, int direction, int status, int mode, boolean mpty, String number, int type)