Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Callback

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/bluetooth/BluetoothHidDevice.Callback "View this page in Java")

```
abstract class Callback
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.bluetooth.BluetoothHidDevice.Callback](https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#) |

The template class that applications use to call callback functions on events from the HID host. Callback functions are wrapped in this class and registered to the Android system during app registration.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#Callback()()` <br /> |

| Public methods ||
|---|---|
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#onAppStatusChanged(android.bluetooth.BluetoothDevice,%20kotlin.Boolean)(pluggedDevice: https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice!, registered: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Callback called when application registration state changes. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#onConnectionStateChanged(android.bluetooth.BluetoothDevice,%20kotlin.Int)(device: https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice!, state: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Callback called when connection state with remote host was changed. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#onGetReport(android.bluetooth.BluetoothDevice,%20kotlin.Byte,%20kotlin.Byte,%20kotlin.Int)(device: https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice!, type: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html, id: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html, bufferSize: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Callback called when GET_REPORT is received from remote host. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#onInterruptData(android.bluetooth.BluetoothDevice,%20kotlin.Byte,%20kotlin.ByteArray)(device: https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice!, reportId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html, data: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html!)` Callback called when report data is received over interrupt channel. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#onSetProtocol(android.bluetooth.BluetoothDevice,%20kotlin.Byte)(device: https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice!, protocol: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html)` Callback called when SET_PROTOCOL is received from remote host. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#onSetReport(android.bluetooth.BluetoothDevice,%20kotlin.Byte,%20kotlin.Byte,%20kotlin.ByteArray)(device: https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice!, type: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html, id: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html, data: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html!)` Callback called when SET_REPORT is received from remote host. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice.Callback#onVirtualCableUnplug(android.bluetooth.BluetoothDevice)(device: https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice!)` Callback called when Virtual Cable is removed. |

## Public constructors

### Callback

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Callback()
```

## Public methods

### onAppStatusChanged

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onAppStatusChanged(
    pluggedDevice: BluetoothDevice!, 
    registered: Boolean
): Unit
```

Callback called when application registration state changes. Usually it's called due to either `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice#registerApp(android.bluetooth.BluetoothHidDeviceAppSdpSettings,%20android.bluetooth.BluetoothHidDeviceAppQosSettings,%20android.bluetooth.BluetoothHidDeviceAppQosSettings,%20java.util.concurrent.Executor,%20android.bluetooth.BluetoothHidDevice.Callback)` or `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice#unregisterApp()` , but can be also unsolicited in case e.g. Bluetooth was turned off in which case application is unregistered automatically.

| Parameters ||
|---|---|
| `pluggedDevice` | [BluetoothDevice](https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice)!: `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice` object which represents host that currently has Virtual Cable established with device. Only valid when application is registered, can be `null`. |
| `registered` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): `true` if application is registered, `false` otherwise. |

### onConnectionStateChanged

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onConnectionStateChanged(
    device: BluetoothDevice!, 
    state: Int
): Unit
```

Callback called when connection state with remote host was changed. Application can assume than Virtual Cable is established when called with `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothProfile#STATE_CONNECTED:kotlin.Int` `state`.

| Parameters ||
|---|---|
| `device` | [BluetoothDevice](https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice)!: `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice` object representing host device which connection state was changed. |
| `state` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): Connection state as defined in `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothProfile`. |

### onGetReport

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onGetReport(
    device: BluetoothDevice!, 
    type: Byte, 
    id: Byte, 
    bufferSize: Int
): Unit
```

Callback called when GET_REPORT is received from remote host. Should be replied by application using `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice#replyReport(android.bluetooth.BluetoothDevice,%20kotlin.Byte,%20kotlin.Byte,%20kotlin.ByteArray)`.

| Parameters ||
|---|---|
| `type` | [Byte](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html): Requested Report Type. |
| `id` | [Byte](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html): Requested Report Id, can be 0 if no Report Id are defined in descriptor. |
| `bufferSize` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): Requested buffer size, application shall respond with at least given number of bytes. |

### onInterruptData

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onInterruptData(
    device: BluetoothDevice!, 
    reportId: Byte, 
    data: ByteArray!
): Unit
```

Callback called when report data is received over interrupt channel. Report Type is assumed to be `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice#REPORT_TYPE_OUTPUT:kotlin.Byte`.

| Parameters ||
|---|---|
| `reportId` | [Byte](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html): Report Id. |
| `data` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!: Report data. |

### onSetProtocol

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onSetProtocol(
    device: BluetoothDevice!, 
    protocol: Byte
): Unit
```

Callback called when SET_PROTOCOL is received from remote host. Application shall use this information to send only reports valid for given protocol mode. By default, `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice#PROTOCOL_REPORT_MODE:kotlin.Byte` shall be assumed.

| Parameters ||
|---|---|
| `protocol` | [Byte](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html): Protocol Mode. |

### onSetReport

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onSetReport(
    device: BluetoothDevice!, 
    type: Byte, 
    id: Byte, 
    data: ByteArray!
): Unit
```

Callback called when SET_REPORT is received from remote host. In case received data are invalid, application shall respond with `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothHidDevice#reportError(android.bluetooth.BluetoothDevice,%20kotlin.Byte)`.

| Parameters ||
|---|---|
| `type` | [Byte](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html): Report Type. |
| `id` | [Byte](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html): Report Id. |
| `data` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!: Report data. |

### onVirtualCableUnplug

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onVirtualCableUnplug(device: BluetoothDevice!): Unit
```

Callback called when Virtual Cable is removed. After this callback is received connection will be disconnected automatically.