Added in API level 28

BluetoothHidDevice


class BluetoothHidDevice : BluetoothProfile
kotlin.Any
   ↳ android.bluetooth.BluetoothHidDevice

Provides the public APIs to control the Bluetooth HID Device profile.

BluetoothHidDevice is a proxy object for controlling the Bluetooth HID Device Service via IPC. Use BluetoothAdapter.getProfileProxy to get the BluetoothHidDevice proxy object.

Summary

Nested classes
abstract

The template class that applications use to call callback functions on events from the HID host.

Constants
static String

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

static Byte

Constant representing error response for Set Report due to "invalid parameter".

static Byte

Constant representing error response for Set Report due to "invalid report ID".

static Byte

Constant representing error response for Set Report due to "not ready".

static Byte

Constant representing success response for Set Report.

static Byte

Constant representing error response for Set Report with unknown reason.

static Byte

Constant representing error response for Set Report due to "unsupported request".

static Byte

Constant representing boot protocol mode used set by host.

static Byte

Constant representing report protocol mode used set by host.

static Byte

Constant representing HID Feature Report type.

static Byte

Constant representing HID Input Report type.

static Byte

Constant representing HID Output Report type.

static Byte

Constant representing combo keyboard and mouse subclass.

static Byte

Constant representing keyboard subclass.

static Byte

Constant representing mouse subclass.

static Byte

Constant representing unspecified HID device subclass.

static Byte

Constant representing card reader subclass.

static Byte

Constant representing digitizer tablet subclass.

static Byte

Constant representing gamepad subclass.

static Byte

Constant representing joystick subclass.

static Byte

Constant representing remote control subclass.

static Byte

Constant representing sensing device subclass.

static Byte

Constant representing uncategorized HID device subclass.

Inherited constants
Public methods
Boolean

Initiates connection to host which is currently paired with this device.

Boolean

Disconnects from currently connected host.

MutableList<BluetoothDevice!>!

Get connected devices for this specific profile.

Int

Get the current connection state of the profile
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).

MutableList<BluetoothDevice!>!

Get a list of devices that match any of the given connection states.

Boolean

Registers application to be used for HID device.

Boolean
replyReport(device: BluetoothDevice!, type: Byte, id: Byte, data: ByteArray!)

Sends report to remote host as reply for GET_REPORT request from android.bluetooth.BluetoothHidDevice.Callback#onGetReport(android.bluetooth.BluetoothDevice,byte,byte,int).

Boolean
reportError(device: BluetoothDevice!, error: Byte)

Sends error handshake message as reply for invalid SET_REPORT request from android.bluetooth.BluetoothHidDevice.Callback#onSetReport(android.bluetooth.BluetoothDevice,byte,byte,byte[]).

Boolean
sendReport(device: BluetoothDevice!, id: Int, data: ByteArray!)

Sends report to remote host using interrupt channel.

Boolean

Unregisters application.

Constants

ACTION_CONNECTION_STATE_CHANGED

Added in API level 28
static val ACTION_CONNECTION_STATE_CHANGED: String

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

This intent will have 3 extras:

EXTRA_STATE or EXTRA_PREVIOUS_STATE can be any of STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED, STATE_DISCONNECTING.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Value: "android.bluetooth.hiddevice.profile.action.CONNECTION_STATE_CHANGED"

ERROR_RSP_INVALID_PARAM

Added in API level 28
static val ERROR_RSP_INVALID_PARAM: Byte

Constant representing error response for Set Report due to "invalid parameter".

Value: 4

ERROR_RSP_INVALID_RPT_ID

Added in API level 28
static val ERROR_RSP_INVALID_RPT_ID: Byte

Constant representing error response for Set Report due to "invalid report ID".

Value: 2

ERROR_RSP_NOT_READY

Added in API level 28
static val ERROR_RSP_NOT_READY: Byte

Constant representing error response for Set Report due to "not ready".

Value: 1

ERROR_RSP_SUCCESS

Added in API level 28
static val ERROR_RSP_SUCCESS: Byte

Constant representing success response for Set Report.

Value: 0

ERROR_RSP_UNKNOWN

Added in API level 28
static val ERROR_RSP_UNKNOWN: Byte

Constant representing error response for Set Report with unknown reason.

Value: 14

ERROR_RSP_UNSUPPORTED_REQ

Added in API level 28
static val ERROR_RSP_UNSUPPORTED_REQ: Byte

Constant representing error response for Set Report due to "unsupported request".

Value: 3

PROTOCOL_BOOT_MODE

Added in API level 28
static val PROTOCOL_BOOT_MODE: Byte

Constant representing boot protocol mode used set by host. Default is always PROTOCOL_REPORT_MODE unless notified otherwise.

Value: 0

PROTOCOL_REPORT_MODE

Added in API level 28
static val PROTOCOL_REPORT_MODE: Byte

Constant representing report protocol mode used set by host. Default is always PROTOCOL_REPORT_MODE unless notified otherwise.

Value: 1

SUBCLASS1_COMBO

Added in API level 28
static val SUBCLASS1_COMBO: Byte

Constant representing combo keyboard and mouse subclass.

Value: -64

See Also

SUBCLASS1_KEYBOARD

Added in API level 28
static val SUBCLASS1_KEYBOARD: Byte

Constant representing keyboard subclass.

Value: 64

See Also

SUBCLASS1_MOUSE

Added in API level 28
static val SUBCLASS1_MOUSE: Byte

Constant representing mouse subclass.

Value: -128

See Also

SUBCLASS1_NONE

Added in API level 28
static val SUBCLASS1_NONE: Byte

Constant representing unspecified HID device subclass.

Value: 0

See Also

SUBCLASS2_CARD_READER

Added in API level 28
static val SUBCLASS2_CARD_READER: Byte

Constant representing card reader subclass.

Value: 6

See Also

SUBCLASS2_DIGITIZER_TABLET

Added in API level 28
static val SUBCLASS2_DIGITIZER_TABLET: Byte

Constant representing digitizer tablet subclass.

Value: 5

See Also

SUBCLASS2_GAMEPAD

Added in API level 28
static val SUBCLASS2_GAMEPAD: Byte

Constant representing gamepad subclass.

Value: 2

See Also

SUBCLASS2_JOYSTICK

Added in API level 28
static val SUBCLASS2_JOYSTICK: Byte

Constant representing joystick subclass.

Value: 1

See Also

SUBCLASS2_REMOTE_CONTROL

Added in API level 28
static val SUBCLASS2_REMOTE_CONTROL: Byte

Constant representing remote control subclass.

Value: 3

See Also

SUBCLASS2_SENSING_DEVICE

Added in API level 28
static val SUBCLASS2_SENSING_DEVICE: Byte

Constant representing sensing device subclass.

Value: 4

See Also

SUBCLASS2_UNCATEGORIZED

Added in API level 28
static val SUBCLASS2_UNCATEGORIZED: Byte

Constant representing uncategorized HID device subclass.

Value: 0

See Also

Public methods

connect

Added in API level 28
fun connect(device: BluetoothDevice!): Boolean

Initiates connection to host which is currently paired with this device. If the application is not registered, #connect(BluetoothDevice) will fail. The connection state should be tracked by the application by handling callback from Callback#onConnectionStateChanged. The connection state is not related to the return value of this method.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
Boolean true if the command is successfully sent; otherwise false.

disconnect

Added in API level 28
fun disconnect(device: BluetoothDevice!): Boolean

Disconnects from currently connected host. The connection state should be tracked by the application by handling callback from Callback#onConnectionStateChanged. The connection state is not related to the return value of this method.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
Boolean true if the command is successfully sent; otherwise false.

getConnectedDevices

Added in API level 28
fun getConnectedDevices(): MutableList<BluetoothDevice!>!

Get connected devices for this specific profile.

Return the set of devices which are in state STATE_CONNECTED
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
MutableList<BluetoothDevice!>! List of devices. The list will be empty on error.

getConnectionState

Added in API level 28
fun getConnectionState(device: BluetoothDevice!): Int

Get the current connection state of the profile
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
device BluetoothDevice!: Remote bluetooth device.
Return
Int State of the profile connection. One of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING Value is android.bluetooth.BluetoothProfile#STATE_DISCONNECTED, android.bluetooth.BluetoothProfile#STATE_CONNECTING, android.bluetooth.BluetoothProfile#STATE_CONNECTED, or android.bluetooth.BluetoothProfile#STATE_DISCONNECTING

getDevicesMatchingConnectionStates

Added in API level 28
fun getDevicesMatchingConnectionStates(states: IntArray!): MutableList<BluetoothDevice!>!

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.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
states IntArray!: Array of states. States can be one of STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING,
Return
MutableList<BluetoothDevice!>! List of devices. The list will be empty on error.

registerApp

Added in API level 28
fun registerApp(
    sdp: BluetoothHidDeviceAppSdpSettings!,
    inQos: BluetoothHidDeviceAppQosSettings!,
    outQos: BluetoothHidDeviceAppQosSettings!,
    executor: Executor!,
    callback: BluetoothHidDevice.Callback!
): Boolean

Registers application to be used for HID device. Connections to HID Device are only possible when application is registered. Only one application can be registered at one time. When an application is registered, the HID Host service will be disabled until it is unregistered. When no longer used, application should be unregistered using unregisterApp(). The app will be automatically unregistered if it is not foreground. The registration status should be tracked by the application by handling callback from Callback#onAppStatusChanged. The app registration status is not related to the return value of this method.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
sdp BluetoothHidDeviceAppSdpSettings!: BluetoothHidDeviceAppSdpSettings object of HID Device SDP record. The HID Device SDP record is required.
inQos BluetoothHidDeviceAppQosSettings!: BluetoothHidDeviceAppQosSettings object of Incoming QoS Settings. The Incoming QoS Settings is not required. Use null or default BluetoothHidDeviceAppQosSettings.Builder for default values.
outQos BluetoothHidDeviceAppQosSettings!: BluetoothHidDeviceAppQosSettings object of Outgoing QoS Settings. The Outgoing QoS Settings is not required. Use null or default BluetoothHidDeviceAppQosSettings.Builder for default values.
executor Executor!: Executor object on which callback will be executed. The Executor object is required.
callback BluetoothHidDevice.Callback!: Callback object to which callback messages will be sent. The Callback object is required.
Return
Boolean true if the command is successfully sent; otherwise false.

replyReport

Added in API level 28
fun replyReport(
    device: BluetoothDevice!,
    type: Byte,
    id: Byte,
    data: ByteArray!
): Boolean

Sends report to remote host as reply for GET_REPORT request from android.bluetooth.BluetoothHidDevice.Callback#onGetReport(android.bluetooth.BluetoothDevice,byte,byte,int).
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
type Byte: Report Type, as in request.
id Byte: Report Id, as in request.
data ByteArray!: Report data, not including Report Id.
Return
Boolean true if the command is successfully sent; otherwise false.

reportError

Added in API level 28
fun reportError(
    device: BluetoothDevice!,
    error: Byte
): Boolean

Sends error handshake message as reply for invalid SET_REPORT request from android.bluetooth.BluetoothHidDevice.Callback#onSetReport(android.bluetooth.BluetoothDevice,byte,byte,byte[]).
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
error Byte: Error to be sent for SET_REPORT via HANDSHAKE.
Return
Boolean true if the command is successfully sent; otherwise false.

sendReport

Added in API level 28
fun sendReport(
    device: BluetoothDevice!,
    id: Int,
    data: ByteArray!
): Boolean

Sends report to remote host using interrupt channel.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
id Int: Report Id, as defined in descriptor. Can be 0 in case Report Id are not defined in descriptor.
data ByteArray!: Report data, not including Report Id.
Return
Boolean true if the command is successfully sent; otherwise false.

unregisterApp

Added in API level 28
fun unregisterApp(): Boolean

Unregisters application. Active connection will be disconnected and no new connections will be allowed until registered again using (android.bluetooth.BluetoothHidDeviceAppQosSettings,android.bluetooth.BluetoothHidDeviceAppQosSettings,android.bluetooth.BluetoothHidDeviceAppQosSettings,java.util.concurrent.Executor,android.bluetooth.BluetoothHidDevice.Callback). The registration status should be tracked by the application by handling callback from Callback#onAppStatusChanged. The app registration status is not related to the return value of this method.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
Boolean true if the command is successfully sent; otherwise false.