Added in API level 28

Callback


abstract class Callback
kotlin.Any
   ↳ 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

Public methods
open Unit
onAppStatusChanged(pluggedDevice: BluetoothDevice!, registered: Boolean)

Callback called when application registration state changes.

open Unit

Callback called when connection state with remote host was changed.

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

Callback called when GET_REPORT is received from remote host.

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

Callback called when report data is received over interrupt channel.

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

Callback called when SET_PROTOCOL is received from remote host.

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

Callback called when SET_REPORT is received from remote host.

open Unit

Callback called when Virtual Cable is removed.

Public constructors

Callback

Added in API level 28
Callback()

Public methods

onAppStatusChanged

Added in API level 28
open fun onAppStatusChanged(
    pluggedDevice: BluetoothDevice!,
    registered: Boolean
): Unit

Callback called when application registration state changes. Usually it's called due to either Executor, Callback) or 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!: BluetoothDevice object which represents host that currently has Virtual Cable established with device. Only valid when application is registered, can be null.
registered Boolean: true if application is registered, false otherwise.

onConnectionStateChanged

Added in API level 28
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 android.bluetooth.BluetoothProfile#STATE_CONNECTED state.

Parameters
device BluetoothDevice!: BluetoothDevice object representing host device which connection state was changed.
state Int: Connection state as defined in BluetoothProfile.

onGetReport

Added in API level 28
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 BluetoothHidDevice#replyReport(BluetoothDevice, byte, byte,.

Parameters
type Byte: Requested Report Type.
id Byte: Requested Report Id, can be 0 if no Report Id are defined in descriptor.
bufferSize Int: Requested buffer size, application shall respond with at least given number of bytes.

onInterruptData

Added in API level 28
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 BluetoothHidDevice#REPORT_TYPE_OUTPUT.

Parameters
reportId Byte: Report Id.
data ByteArray!: Report data.

onSetProtocol

Added in API level 28
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, android.bluetooth.BluetoothHidDevice#PROTOCOL_REPORT_MODE shall be assumed.

Parameters
protocol Byte: Protocol Mode.

onSetReport

Added in API level 28
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 android.bluetooth.BluetoothHidDevice#reportError(android.bluetooth.BluetoothDevice,byte).

Parameters
type Byte: Report Type.
id Byte: Report Id.
data ByteArray!: Report data.

onVirtualCableUnplug

Added in API level 28
open fun onVirtualCableUnplug(device: BluetoothDevice!): Unit

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