# BluetoothConnectionCallback

# BluetoothConnectionCallback

`
public


interface
BluetoothConnectionCallback
`  
`


`

|-----------------------------------------------------------------|
| com.google.android.things.bluetooth.BluetoothConnectionCallback |

<br />

*** ** * ** ***

This callback is invoked when the device receives requests for Bluetooth profile connections and contains relevant information to handle the connection process.

## Summary

|                                                                                                                                                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                                                                                                                                                 ||
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` default void` | ` `[onConnected](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback#onConnected(android.bluetooth.BluetoothDevice, int))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, int profile) ` Invoked when a connection for a profile has been established with the remote device.                                                                                                                                                                                                                                                                                                                           |
| ` default void` | ` `[onConnectionRequestCancelled](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback#onConnectionRequestCancelled(android.bluetooth.BluetoothDevice, int))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, int requestType) ` Invoked when a prior connection request notified using[onConnectionRequested(BluetoothDevice, ConnectionParams)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback#onConnectionRequested(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.ConnectionParams))has been cancelled or timed out. |
| ` default void` | ` `[onConnectionRequested](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback#onConnectionRequested(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.ConnectionParams))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, `[ConnectionParams](https://developer.android.com/reference/com/google/android/things/bluetooth/ConnectionParams)` connectionParams) ` Invoked when a remote device requests a connection.                                                                                                                                                               |
| ` default void` | ` `[onDisconnected](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback#onDisconnected(android.bluetooth.BluetoothDevice, int))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html)` bluetoothDevice, int profile) ` Invoked when a Bluetooth connection for a profile is disconnected from the remote device.                                                                                                                                                                                                                                                                                                                |

## Public methods

### onConnected

```
void onConnected (BluetoothDevice bluetoothDevice, 
                int profile)
```

Invoked when a connection for a profile has been established with the remote device.

<br />

|                                                                              Parameters                                                                              ||
|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br />                                                                                                |
| `profile`         | `int`:[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)which was connected. <br /> |

### onConnectionRequestCancelled

```
void onConnectionRequestCancelled (BluetoothDevice bluetoothDevice, 
                int requestType)
```

Invoked when a prior connection request notified using[onConnectionRequested(BluetoothDevice, ConnectionParams)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionCallback#onConnectionRequested(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.ConnectionParams))has been cancelled or timed out.

This callback implies that the previous connection request has expired and the connection should be attempted again.

<br />

|                                                                                                                                                                                                                                                                                                                                             Parameters                                                                                                                                                                                                                                                                                                                                             ||
|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `requestType`     | `int`: Type of access request. One of[REQUEST_TYPE_PROFILE_CONNECTION](https://developer.android.com/reference/com/google/android/things/bluetooth/ConnectionParams#REQUEST_TYPE_PROFILE_CONNECTION),[REQUEST_TYPE_PHONEBOOK_ACCESS](https://developer.android.com/reference/com/google/android/things/bluetooth/ConnectionParams#REQUEST_TYPE_PHONEBOOK_ACCESS),[REQUEST_TYPE_MESSAGE_ACCESS](https://developer.android.com/reference/com/google/android/things/bluetooth/ConnectionParams#REQUEST_TYPE_MESSAGE_ACCESS),[REQUEST_TYPE_SIM_ACCESS](https://developer.android.com/reference/com/google/android/things/bluetooth/ConnectionParams#REQUEST_TYPE_SIM_ACCESS) <br /> |

### onConnectionRequested

```
void onConnectionRequested (BluetoothDevice bluetoothDevice, 
                ConnectionParams connectionParams)
```

Invoked when a remote device requests a connection. The connection can be generic or for specific profile types. It is the responsibility of the calling code to convey this information to the user and obtain consent.

Once the calling code has obtained user consent, they may confirm/deny the connection request using[confirmOrDenyConnection(BluetoothDevice, ConnectionParams, boolean)](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConnectionManager#confirmOrDenyConnection(android.bluetooth.BluetoothDevice, com.google.android.things.bluetooth.ConnectionParams, boolean)).

<br />

|                                                     Parameters                                                     ||
|--------------------|------------------------------------------------------------------------------------------------|
| `bluetoothDevice`  | `BluetoothDevice`: remote Bluetooth device. <br />                                             |
| `connectionParams` | `ConnectionParams`: Contains all the required information about the connection request. <br /> |

### onDisconnected

```
void onDisconnected (BluetoothDevice bluetoothDevice, 
                int profile)
```

Invoked when a Bluetooth connection for a profile is disconnected from the remote device.

<br />

|                                                                               Parameters                                                                                ||
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `bluetoothDevice` | `BluetoothDevice`: remote Bluetooth device. <br />                                                                                                   |
| `profile`         | `int`:[BluetoothProfile](https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothProfile)which was disconnected. <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)