# BluetoothConnectionManager

Summary:[Constants](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#constants)\|[Methods](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#)  

# BluetoothConnectionManager

`
public


class
BluetoothConnectionManager
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|----------------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | com.google.android.things.bluetooth.BluetoothConnectionManager |

<br />

*** ** * ** ***

This class is responsible for handling Bluetooth pairing and connections with a remote[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)

It allows developers to perform the following main operations.

1. Initiate pairing with a new device
2. Remove existing bond with a known device
3. Control the pairing flow via user consent/input, and confirm pairing for outgoing and incoming pairing requests.
4. Establish profile connections with a remote Bluetooth device
5. Disconnect existing profile connections with a remote device
6. Obtain user consent for incoming connection requests and confirm/deny them

This class should not be used for GATT profiles[GATT](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#GATT)and[GATT_SERVER](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#GATT_SERVER). For GATT, use[BluetoothGatt](https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html),[BluetoothGattServer](https://developer.android.com/reference/android/bluetooth/BluetoothGattServer.html)and[BluetoothManager](https://developer.android.com/reference/android/bluetooth/BluetoothManager.html)

## Summary

|                                                                                                    ### Constants                                                                                                    ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [STATE_CONNECTED](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#STATE_CONNECTED) Bluetooth profile is in a connected state.                         |
| `int` | [STATE_CONNECTING](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#STATE_CONNECTING) Bluetooth profile is attempting to establish a connection.       |
| `int` | [STATE_DISCONNECTED](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#STATE_DISCONNECTED) Bluetooth profile is in a disconnected state.                |
| `int` | [STATE_DISCONNECTING](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#STATE_DISCONNECTING) Bluetooth profile is disconnecting an existing connection. |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ||
|------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`                                                                                                                                     | ` `[cancelPairing](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#cancelPairing(android.bluetooth.BluetoothDevice))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice) ` Cancel an ongoing pairing process with a remote device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                                                        | ` `[confirmOrDenyConnection](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#confirmOrDenyConnection(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.ConnectionParams, boolean))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, `[ConnectionParams](https://developer.android.com/reference/com/google/android/things/bluetooth/ConnectionParams)` connectionParams, boolean result) ` This function should only be called in response to[onConnectionRequested(BluetoothDevice, ConnectionParams)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback#onConnectionRequested(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.ConnectionParams))and can be used to either confirm or deny a connection request from a remote Bluetooth device. |
| ` boolean`                                                                                                                                     | ` `[connect](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#connect(android.bluetooth.BluetoothDevice, int))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, int bluetoothProfile) ` Establishes a connection with the remote bluetooth device over the specified[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile).                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` boolean`                                                                                                                                     | ` `[connect](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#connect(android.bluetooth.BluetoothDevice))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice) ` Establishes a connection with the provided remote bluetooth device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` boolean`                                                                                                                                     | ` `[disconnect](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#disconnect(android.bluetooth.BluetoothDevice, int))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, int bluetoothProfile) ` Disconnects the connection for the specified[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)with the remote device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` boolean`                                                                                                                                     | ` `[disconnect](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#disconnect(android.bluetooth.BluetoothDevice))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice) ` Disconnects all existing profile connections with the remote device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` boolean`                                                                                                                                     | ` `[finishPairing](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#finishPairing(android.bluetooth.BluetoothDevice))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice) ` Invoke this function to finish the pairing process with the remote device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ` boolean`                                                                                                                                     | ` `[finishPairing](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#finishPairing(android.bluetooth.BluetoothDevice, java.lang.String))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, `[String](https://developer.android.com/reference/java/lang/String)` pairingPin) ` Invoke this function to finish the pairing process with the remote device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` `[List](https://developer.android.com/reference/java/util/List)`<`[Integer](https://developer.android.com/reference/java/lang/Integer)`>`    | ` `[getConnectableProfiles](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#getConnectableProfiles(android.bluetooth.BluetoothDevice))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice) ` Returns all the Bluetooth Profiles which are connectable from the local device to the remote device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` int`                                                                                                                                         | ` `[getConnectionState](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#getConnectionState(android.bluetooth.BluetoothDevice, int))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, int bluetoothProfile) ` Returns the connection state of the specified[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)with the remote[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html).                                                                                                                                                                                                                                                                                                                                                        |
| ` static `[BluetoothConnectionManager](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager) | ` `[getInstance](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#getInstance())`() ` Returns an instance of[BluetoothConnectionManager](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager)which can be used to control Bluetooth pairing/connections with a remote[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` boolean`                                                                                                                                     | ` `[initiatePairing](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#initiatePairing(android.bluetooth.BluetoothDevice))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice) ` Initiate Bluetooth pairing process with a remote device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                                        | ` `[registerConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#registerConnectionCallback(com.google.android.things.bluetooth.BluetoothConnectionCallback))`(`[BluetoothConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback)` bluetoothConnectionCallback) ` Register a[BluetoothConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback).                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ` void`                                                                                                                                        | ` `[registerPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#registerPairingCallback(com.google.android.things.bluetooth.BluetoothPairingCallback))`(`[BluetoothPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback)` bluetoothPairingCallback) ` Register a[BluetoothPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback).                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` boolean`                                                                                                                                     | ` `[unpair](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#unpair(android.bluetooth.BluetoothDevice))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice) ` Destroys the existing pairing/bond with the remote device.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                                        | ` `[unregisterConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#unregisterConnectionCallback(com.google.android.things.bluetooth.BluetoothConnectionCallback))`(`[BluetoothConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback)` bluetoothConnectionCallback) ` Unregister a[BluetoothConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback).                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` void`                                                                                                                                        | ` `[unregisterPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#unregisterPairingCallback(com.google.android.things.bluetooth.BluetoothPairingCallback))`(`[BluetoothPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback)` bluetoothPairingCallback) ` Unregister a[BluetoothPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback).                                                                                                                                                                                                                                                                                                                                                                                                                                   |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                                                                                                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                                                                                                                                                                                                                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                                                                                                                                                                                                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                                                                                                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                                                                                                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                                                                                                                                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                                                                                                                                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                                                                                                                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long, int))`(long millis, int nanos) ` Causes the current thread to wait until another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#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](https://developer.android.com/reference/java/lang/Object#wait(long))`(long millis) ` Causes the current thread to wait until either another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#notifyAll())method for this object, or a specified amount of time has elapsed.                                                                 | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#notifyAll())method for this object.                                                                                                                                  | ||

## Constants

### STATE_CONNECTED

```
int STATE_CONNECTED
```

Bluetooth profile is in a connected state.

<br />

Constant Value: 2 (0x00000002)  

### STATE_CONNECTING

```
int STATE_CONNECTING
```

Bluetooth profile is attempting to establish a connection.

<br />

Constant Value: 1 (0x00000001)  

### STATE_DISCONNECTED

```
int STATE_DISCONNECTED
```

Bluetooth profile is in a disconnected state.

<br />

Constant Value: 0 (0x00000000)  

### STATE_DISCONNECTING

```
int STATE_DISCONNECTING
```

Bluetooth profile is disconnecting an existing connection.

<br />

Constant Value: 3 (0x00000003)

## Public methods

### cancelPairing

```
boolean cancelPairing (BluetoothDevice bluetoothDevice)
```

Cancel an ongoing pairing process with a remote device.

<br />

|                              Parameters                               ||
|-------------------|----------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

|                                                                        Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.           |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the service has died. |

### confirmOrDenyConnection

```
void confirmOrDenyConnection (BluetoothDevice bluetoothDevice, 
                ConnectionParams connectionParams, 
                boolean result)
```

This function should only be called in response to[onConnectionRequested(BluetoothDevice, ConnectionParams)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback#onConnectionRequested(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.ConnectionParams))and can be used to either confirm or deny a connection request from a remote Bluetooth device.

<br />

|                                         Parameters                                          ||
|--------------------|-------------------------------------------------------------------------|
| `bluetoothDevice`  | `BluetoothDevice`: remote Bluetooth device. <br />                      |
| `connectionParams` | `ConnectionParams`: Parameters for current connection request. <br />   |
| `result`           | `boolean`: whether the connection request was accepted/rejected. <br /> |

### connect

```
boolean connect (BluetoothDevice bluetoothDevice, 
                int bluetoothProfile)
```

Establishes a connection with the remote bluetooth device over the specified[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile).

This method attempts to connect with a remote device over the specified profile regardless of whether the remote device is known to support it or not, as reported by[getConnectableProfiles(BluetoothDevice)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#getConnectableProfiles(android.bluetooth.BluetoothDevice)). This allows the user of the API to force a connection in cases where a device may support a particular profile but does not advertise it through[getUuids()](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids()).

Only the following profiles are currently supported by this method. Supported Profiles:[HEADSET](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#HEADSET),[A2DP](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP),[A2DP_SINK](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP_SINK).

<br />

|                                                                            Parameters                                                                            ||
|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `bluetoothDevice`  | `BluetoothDevice`: remote Bluetooth device. <br />                                                                                           |
| `bluetoothProfile` | `int`: The[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)to connect. <br /> |

|                                            Returns                                            ||
|-----------|------------------------------------------------------------------------------------|
| `boolean` | False if connection infeasible or connection attempt fails. True otherwise. <br /> |

|                                                                       Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.          |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the server has died. |

### connect

```
boolean connect (BluetoothDevice bluetoothDevice)
```

Establishes a connection with the provided remote bluetooth device. This method attempts to establish a connection over all connectable Bluetooth Profiles, as reported by[getConnectableProfiles(BluetoothDevice)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#getConnectableProfiles(android.bluetooth.BluetoothDevice)).

Only the following profiles are currently supported by this method. Supported Profiles:[HEADSET](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#HEADSET),[A2DP](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP),[A2DP_SINK](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP_SINK).

<br />

|                              Parameters                               ||
|-------------------|----------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br /> |

|                                                            Returns                                                             ||
|-----------|---------------------------------------------------------------------------------------------------------------------|
| `boolean` | False if no supported connectable profiles exist and if any of the connection attempts fail. True otherwise. <br /> |

|                                                                       Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.          |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the server has died. |

**See also:**

- [getConnectableProfiles(BluetoothDevice)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#getConnectableProfiles(android.bluetooth.BluetoothDevice))  

### disconnect

```
boolean disconnect (BluetoothDevice bluetoothDevice, 
                int bluetoothProfile)
```

Disconnects the connection for the specified[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)with the remote device.

Only the following profiles are currently supported by this method. Supported Profiles:[HEADSET](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#HEADSET),[A2DP](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP),[A2DP_SINK](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP_SINK),[SAP](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#SAP).

<br />

|                               Parameters                               ||
|--------------------|----------------------------------------------------|
| `bluetoothDevice`  | `BluetoothDevice`: remote Bluetooth device. <br /> |
| `bluetoothProfile` | `int` <br />                                       |

|                                             Returns                                              ||
|-----------|---------------------------------------------------------------------------------------|
| `boolean` | False if no connection exists or the disconnect attempt fails. True otherwise. <br /> |

|                                                                       Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.          |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the server has died. |

### disconnect

```
boolean disconnect (BluetoothDevice bluetoothDevice)
```

Disconnects all existing profile connections with the remote device.

Only the following profiles are currently supported by this method. Supported Profiles:[HEADSET](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#HEADSET),[A2DP](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP),[A2DP_SINK](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP_SINK),[SAP](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#SAP).

<br />

|                              Parameters                               ||
|-------------------|----------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br /> |

|                                                              Returns                                                              ||
|-----------|------------------------------------------------------------------------------------------------------------------------|
| `boolean` | False if no connection exists with the remote device or if any of the disconnect attempts fail. True otherwise. <br /> |

|                                                                       Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.          |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the server has died. |

### finishPairing

```
boolean finishPairing (BluetoothDevice bluetoothDevice)
```

Invoke this function to finish the pairing process with the remote device. Should be called only after receiving a callback from[onPairingInitiated(BluetoothDevice, PairingParams)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback#onPairingInitiated(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.PairingParams)).

This function should be used for pairing variants[PAIRING_VARIANT_CONSENT](https://developer.android.com/reference/com/google/android/things/bluetooth/PairingParams#PAIRING_VARIANT_CONSENT),[PAIRING_VARIANT_PASSKEY_CONFIRMATION](https://developer.android.com/reference/com/google/android/things/bluetooth/PairingParams#PAIRING_VARIANT_PASSKEY_CONFIRMATION).

<br />

|                              Parameters                               ||
|-------------------|----------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

|                                                                        Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.           |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the service has died. |

### finishPairing

```
boolean finishPairing (BluetoothDevice bluetoothDevice, 
                String pairingPin)
```

Invoke this function to finish the pairing process with the remote device. Should be called only after receiving a callback from[onPairingInitiated(BluetoothDevice, PairingParams)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback#onPairingInitiated(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.PairingParams)).

This function should be used for pairing variants[PAIRING_VARIANT_PIN](https://developer.android.com/reference/com/google/android/things/bluetooth/PairingParams#PAIRING_VARIANT_PIN),[PAIRING_VARIANT_PIN_16_DIGITS](https://developer.android.com/reference/com/google/android/things/bluetooth/PairingParams#PAIRING_VARIANT_PIN_16_DIGITS).

<br />

|                              Parameters                               ||
|-------------------|----------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br /> |
| `pairingPin`      | `String`: Pairing pin <br />                       |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

|                                                                        Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.           |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the service has died. |

### getConnectableProfiles

```
List<Integer> getConnectableProfiles (BluetoothDevice bluetoothDevice)
```

Returns all the Bluetooth Profiles which are connectable from the local device to the remote device. This is determined by the Bluetooth service UUIDs advertised by the remote device and the capabilities of the local Bluetooth device.

For example, if the local device is an A2DP source[A2DP](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP)and the remote device an A2DP sink[A2DP_SINK](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP_SINK)then[A2DP](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile#A2DP)would be one of the connectable profiles.

<br />

|                              Parameters                               ||
|-------------------|----------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br /> |

|                                                                                                                                                     Returns                                                                                                                                                     ||
|------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [List](https://developer.android.com/reference/java/util/List)`<`[Integer](https://developer.android.com/reference/java/lang/Integer)`>` | List\<[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)\> of all connectable BluetoothProfiles. <br /> |

|                                                                        Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.           |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the service has died. |

### getConnectionState

```
int getConnectionState (BluetoothDevice bluetoothDevice, 
                int bluetoothProfile)
```

Returns the connection state of the specified[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)with the remote[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html).

<br />

|                                                                            Parameters                                                                            ||
|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `bluetoothDevice`  | `BluetoothDevice`: remote Bluetooth device. <br />                                                                                           |
| `bluetoothProfile` | `int`: The[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)to connect. <br /> |

|                                      Returns                                      ||
|-------|----------------------------------------------------------------------------|
| `int` | the connection state of bluetoothProfile with the Bluetooth device. <br /> |

|                                                                       Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.          |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the server has died. |

### getInstance

```
BluetoothConnectionManager getInstance ()
```

Returns an instance of[BluetoothConnectionManager](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager)which can be used to control Bluetooth pairing/connections with a remote[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html).

<br />

|                                                                   Returns                                                                    ||
|--------------------------------------------------------------------------------------------------------------------------------------|--------|
| [BluetoothConnectionManager](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager) | <br /> |

|                                                                              Throws                                                                              ||
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if a connection cannot be established to the back-end service. |

### initiatePairing

```
boolean initiatePairing (BluetoothDevice bluetoothDevice)
```

Initiate Bluetooth pairing process with a remote device.

<br />

|                              Parameters                               ||
|-------------------|----------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

|                                                                        Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.           |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the service has died. |

### registerConnectionCallback

```
void registerConnectionCallback (BluetoothConnectionCallback bluetoothConnectionCallback)
```

Register a[BluetoothConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback). This allows you to listen for Bluetooth connection events such as incoming connection requests, connection/disconnection of profiles etc.

<br />

|                                             Parameters                                              ||
|-------------------------------|----------------------------------------------------------------------|
| `bluetoothConnectionCallback` | `BluetoothConnectionCallback`: Bluetooth Connection callback. <br /> |

### registerPairingCallback

```
void registerPairingCallback (BluetoothPairingCallback bluetoothPairingCallback)
```

Register a[BluetoothPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback). This allows you to listen for Bluetooth pairing events such as incoming pairing request, devices paired/unpaired etc.

<br />

|                                         Parameters                                         ||
|----------------------------|----------------------------------------------------------------|
| `bluetoothPairingCallback` | `BluetoothPairingCallback`: Bluetooth Pairing callback. <br /> |

### unpair

```
boolean unpair (BluetoothDevice bluetoothDevice)
```

Destroys the existing pairing/bond with the remote device. This also severs any existing Bluetooth profile connections with the remote remote device.

Any future connection attempts will have to undergo the pairing process again, and the local Bluetooth adapter will have no memory/record of the remote device.

<br />

|                              Parameters                               ||
|-------------------|----------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

|                                                                        Throws                                                                        ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | when the Bluetooth device is null.           |
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)       | when the connection to the service has died. |

### unregisterConnectionCallback

```
void unregisterConnectionCallback (BluetoothConnectionCallback bluetoothConnectionCallback)
```

Unregister a[BluetoothConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback). This function needs to be invoked to ensure proper clearing up of resources, and should be called once you don't need to listen to connection events.

<br />

|                                             Parameters                                              ||
|-------------------------------|----------------------------------------------------------------------|
| `bluetoothConnectionCallback` | `BluetoothConnectionCallback`: Bluetooth Connection callback. <br /> |

### unregisterPairingCallback

```
void unregisterPairingCallback (BluetoothPairingCallback bluetoothPairingCallback)
```

Unregister a[BluetoothPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback). This function needs to be invoked to ensure proper clearing up of resources, and should be called once you don't need to listen to pairing events.

<br />

|                                         Parameters                                         ||
|----------------------------|----------------------------------------------------------------|
| `bluetoothPairingCallback` | `BluetoothPairingCallback`: Bluetooth Pairing callback. <br /> |

-

  ## Interfaces

  - [BluetoothConnectionCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback)
  - [BluetoothPairingCallback](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback)
-

  ## Classes

  - [BluetoothClassFactory](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothClassFactory)
  - [BluetoothConfigManager](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConfigManager)
  - [BluetoothConnectionManager](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager)
  - [BluetoothPairingCallback.PairingError](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothPairingCallback.PairingError)
  - [BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)
  - [BluetoothProfileManager](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfileManager)
  - [ConnectionParams](https://developer.android.com/reference/com/google/android/things/bluetooth/ConnectionParams)
  - [PairingParams](https://developer.android.com/reference/com/google/android/things/bluetooth/PairingParams)