# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Constants | Inherited Constants | Methods | Inherited Methods

# BluetoothHeadset

`public final class BluetoothHeadset`
`extends Object` `implements BluetoothProfile`

java.lang.Object
↳ | android.bluetooth.BluetoothHeadset

Public API for controlling the Bluetooth Headset Service. This includes both Bluetooth Headset and Handsfree (v1.5) profiles.

BluetoothHeadset is a proxy object for controlling the Bluetooth Headset Service via IPC.

Use `BluetoothAdapter#getProfileProxy` to get the BluetoothHeadset proxy object. Use `BluetoothAdapter#closeProfileProxy` to close the service connection.

Android only supports one connected Bluetooth Headset at a time. Each method is protected with its appropriate permission.

## Summary

### Constants
`String` | `ACTION_AUDIO_STATE_CHANGED` Intent used to broadcast the change in the Audio Connection state of the HDP profile.
`String` | `ACTION_CONNECTION_STATE_CHANGED` Intent used to broadcast the change in connection state of the Headset profile.
`String` | `ACTION_VENDOR_SPECIFIC_HEADSET_EVENT` Intent used to broadcast that the headset has posted a vendor-specific event.
`int` | `AT_CMD_TYPE_ACTION` AT command type ACTION used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, AT+CHUP.
`int` | `AT_CMD_TYPE_BASIC` AT command type BASIC used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, ATD.
`int` | `AT_CMD_TYPE_READ` AT command type READ used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, AT+VGM?.
`int` | `AT_CMD_TYPE_SET` AT command type SET used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, AT+VGM=.
`int` | `AT_CMD_TYPE_TEST` AT command type TEST used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, AT+VGM=?.
`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.
`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.
`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.
`int` | `STATE_AUDIO_CONNECTED` Headset state when SCO audio is connected.
`int` | `STATE_AUDIO_CONNECTING` Headset state when SCO audio is connecting.
`int` | `STATE_AUDIO_DISCONNECTED` Headset state when SCO audio is not connected.
`String` | `VENDOR_RESULT_CODE_COMMAND_ANDROID` A vendor-specific command for unsolicited result code.
`String` | `VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY` The intent category to be used with `ACTION_VENDOR_SPECIFIC_HEADSET_EVENT` for the companyId

### Inherited constants
From interface `android.bluetooth.BluetoothProfile`
`int` | `A2DP` A2DP profile.
`String` | `EXTRA_PREVIOUS_STATE` Extra for the connection state intents of the individual profiles.
`String` | `EXTRA_STATE` Extra for the connection state intents of the individual profiles.
`int` | `GATT` GATT
`int` | `GATT_SERVER` GATT_SERVER
`int` | `HEADSET` Headset and Handsfree profile
`int` | `HEALTH` This constant is deprecated. Health Device Profile (HDP) and MCAP protocol are no longer used. New apps should use Bluetooth Low Energy based solutions such as `BluetoothGatt`, `BluetoothAdapter#listenUsingL2capChannel()`, or `BluetoothDevice#createL2capChannel(int)`
`int` | `HEARING_AID` Hearing Aid Device
`int` | `HID_DEVICE` HID Device
`int` | `SAP`
`int` | `STATE_CONNECTED` The profile is in connected state
`int` | `STATE_CONNECTING` The profile is in connecting state
`int` | `STATE_DISCONNECTED` The profile is in disconnected state
`int` | `STATE_DISCONNECTING` The profile is in disconnecting state

### Public methods
`List<BluetoothDevice>` | `getConnectedDevices()` Get connected devices for this specific profile.
`int` | `getConnectionState(BluetoothDevice device)` Get the current connection state of the profile Requires `Manifest.permission.BLUETOOTH`
`List<BluetoothDevice>` | `getDevicesMatchingConnectionStates(int[] states)` Get a list of devices that match any of the given connection states.
`boolean` | `isAudioConnected(BluetoothDevice device)` Check if Bluetooth SCO audio is connected.
`boolean` | `sendVendorSpecificResultCode(BluetoothDevice device, String command, String arg)` Sends a vendor-specific unsolicited result code to the headset.
`boolean` | `startVoiceRecognition(BluetoothDevice device)` Start Bluetooth voice recognition.
`boolean` | `stopVoiceRecognition(BluetoothDevice device)` Stop Bluetooth Voice Recognition mode, and shut down the Bluetooth audio path.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.
From interface `android.bluetooth.BluetoothProfile`
`abstract List<BluetoothDevice>` | `getConnectedDevices()` Get connected devices for this specific profile.
`abstract int` | `getConnectionState(BluetoothDevice device)` Get the current connection state of the profile Requires `Manifest.permission.BLUETOOTH`
`abstract List<BluetoothDevice>` | `getDevicesMatchingConnectionStates(int[] states)` Get a list of devices that match any of the given connection states.

## Constants

### ACTION_AUDIO_STATE_CHANGED

    public static final String ACTION_AUDIO_STATE_CHANGED

Intent used to broadcast the change in the Audio Connection state of the HDP profile.

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 `Manifest.permission.BLUETOOTH` permission to receive.

Constant Value: "android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED"

### ACTION_CONNECTION_STATE_CHANGED

    public static final String ACTION_CONNECTION_STATE_CHANGED

Intent used to broadcast the change in connection state of the Headset profile.

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 `Manifest.permission.BLUETOOTH` permission to receive.

Constant Value: "android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED"

### ACTION_VENDOR_SPECIFIC_HEADSET_EVENT

    public static final String ACTION_VENDOR_SPECIFIC_HEADSET_EVENT

Intent used to broadcast that the headset has posted a vendor-specific 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

- EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD = +XEVENT
- EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE = AT_CMD_TYPE_SET
- EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS = foo, 3

Requires `Manifest.permission.BLUETOOTH` permission to receive.

Constant Value: "android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT"

### AT_CMD_TYPE_ACTION

    public static final int AT_CMD_TYPE_ACTION

AT command type ACTION used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, AT+CHUP. There are no arguments for action commands.

Constant Value: 4 (0x00000004)

### AT_CMD_TYPE_BASIC

    public static final int AT_CMD_TYPE_BASIC

AT command type BASIC used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, ATD. Single character commands and everything following the character are arguments.

Constant Value: 3 (0x00000003)

### AT_CMD_TYPE_READ

    public static final int AT_CMD_TYPE_READ

AT command type READ used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, AT+VGM?. There are no arguments for this command type.

Constant Value: 0 (0x00000000)

### AT_CMD_TYPE_SET

    public static final int AT_CMD_TYPE_SET

AT command type SET used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, AT+VGM=.

Constant Value: 2 (0x00000002)

### AT_CMD_TYPE_TEST

    public static final int AT_CMD_TYPE_TEST

AT command type TEST used with `EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE` For example, AT+VGM=?. There are no arguments for this command type.

Constant Value: 1 (0x00000001)

### EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS

    public static final 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.

Constant Value: "android.bluetooth.headset.extra.VENDOR_SPECIFIC_HEADSET_EVENT_ARGS"

### EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD

    public static final 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.

Constant Value: "android.bluetooth.headset.extra.VENDOR_SPECIFIC_HEADSET_EVENT_CMD"

### EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE

    public static final 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.

Constant Value: "android.bluetooth.headset.extra.VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE"

### STATE_AUDIO_CONNECTED

    public static final int STATE_AUDIO_CONNECTED

Headset state when SCO audio is connected. This state can be one of `BluetoothProfile.EXTRA_STATE` or `BluetoothProfile.EXTRA_PREVIOUS_STATE` of `ACTION_AUDIO_STATE_CHANGED` intent.

Constant Value: 12 (0x0000000c)

### STATE_AUDIO_CONNECTING

    public static final int STATE_AUDIO_CONNECTING

Headset state when SCO audio is connecting. This state can be one of `BluetoothProfile.EXTRA_STATE` or `BluetoothProfile.EXTRA_PREVIOUS_STATE` of `ACTION_AUDIO_STATE_CHANGED` intent.

Constant Value: 11 (0x0000000b)

### STATE_AUDIO_DISCONNECTED

    public static final int STATE_AUDIO_DISCONNECTED

Headset state when SCO audio is not connected. This state can be one of `BluetoothProfile.EXTRA_STATE` or `BluetoothProfile.EXTRA_PREVIOUS_STATE` of `ACTION_AUDIO_STATE_CHANGED` intent.

Constant Value: 10 (0x0000000a)

### VENDOR_RESULT_CODE_COMMAND_ANDROID

    public static final String VENDOR_RESULT_CODE_COMMAND_ANDROID

A vendor-specific command for unsolicited result code.

Constant Value: "+ANDROID"

### VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY

    public static final String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY

The intent category to be used with `ACTION_VENDOR_SPECIFIC_HEADSET_EVENT` for the companyId

Constant Value: "android.bluetooth.headset.intent.category.companyid"

## Public methods

### getConnectedDevices

    public List<BluetoothDevice> getConnectedDevices ()

Get connected devices for this specific profile.

Return the set of devices which are in state `STATE_CONNECTED`
Requires `Manifest.permission.BLUETOOTH`

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

### getConnectionState

    public int getConnectionState (BluetoothDevice device)

Get the current connection state of the profile
Requires `Manifest.permission.BLUETOOTH`

Parameters
`device` | `BluetoothDevice`: Remote bluetooth device.

Returns
`int` | State of the profile connection. One of `STATE_CONNECTED`, `STATE_CONNECTING`, `STATE_DISCONNECTED`, `STATE_DISCONNECTING` Value is `STATE_DISCONNECTED`, `STATE_CONNECTING`, `STATE_CONNECTED`, or `STATE_DISCONNECTING`

### getDevicesMatchingConnectionStates

    public 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 `Manifest.permission.BLUETOOTH`

Parameters
`states` | `int`: Array of states. States can be one of `BluetoothProfile.STATE_CONNECTED`, `BluetoothProfile.STATE_CONNECTING`, `BluetoothProfile.STATE_DISCONNECTED`, `BluetoothProfile.STATE_DISCONNECTING`,

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

### isAudioConnected

    public boolean isAudioConnected (BluetoothDevice device)

Check if Bluetooth SCO audio is connected.

Requires `Manifest.permission.BLUETOOTH` permission.

Parameters
`device` | `BluetoothDevice`: Bluetooth headset

Returns
`boolean` | true if SCO is connected, false otherwise or on error

### sendVendorSpecificResultCode

    public boolean sendVendorSpecificResultCode (BluetoothDevice device,
                    String command,
                    String arg)

Sends a vendor-specific unsolicited result code to the headset.

The actual string to be sent is `command + ": " + arg`. For example, if `command` is `VENDOR_RESULT_CODE_COMMAND_ANDROID` and `arg` is `"0"`, the string `"+ANDROID: 0"` will be sent.

Currently only `VENDOR_RESULT_CODE_COMMAND_ANDROID` is allowed as `command`.

Requires `Manifest.permission.BLUETOOTH` permission.

Parameters
`device` | `BluetoothDevice`: Bluetooth headset.
`command` | `String`: A vendor-specific command.
`arg` | `String`: The argument that will be attached to the command.

Returns
`boolean` | `false` if there is no headset connected, or if the command is not an allowed vendor-specific unsolicited result code, or on error. `true` otherwise.

Throws
`IllegalArgumentException` | if `command` is `null`.

### startVoiceRecognition

    public boolean startVoiceRecognition (BluetoothDevice device)

Start Bluetooth voice recognition. This methods sends the voice recognition AT command to the headset and establishes the audio connection.

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 `Manifest.permission.BLUETOOTH` permission.

Parameters
`device` | `BluetoothDevice`: Bluetooth headset

Returns
`boolean` | false if there is no headset connected, or the connected headset doesn't support voice recognition, or voice recognition is already started, or audio channel is occupied, or on error, true otherwise

### stopVoiceRecognition

    public boolean stopVoiceRecognition (BluetoothDevice device)

Stop Bluetooth Voice Recognition mode, and shut down the Bluetooth audio path.

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_DISCONNECTED`.

Requires `Manifest.permission.BLUETOOTH` permission.

Parameters
`device` | `BluetoothDevice`: Bluetooth headset

Returns
`boolean` | false if there is no headset connected, or voice recognition has not started, or voice recognition has ended on this headset, or on error, true otherwise

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*