1# @ohos.bluetooth.hid (蓝牙hid模块)(系统接口) 2 3<!--Kit: Connectivity Kit--> 4<!--Subsystem: Communication--> 5<!--Owner: @enjoy_sunshine--> 6<!--Designer: @chengguohong; @tangjia15--> 7<!--Tester: @wangfeng517--> 8<!--Adviser: @zhang_yixin13--> 9 10hid模块提供了访问蓝牙hid相关功能的方法。 11 12> **说明:** 13> 14> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 15> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.hid (蓝牙hid模块)](js-apis-bluetooth-hid.md)。 16 17 18## 导入模块 19 20```js 21import { hid } from '@kit.ConnectivityKit'; 22``` 23 24## HidHostProfile 25 26使用HidHostProfile方法之前需要创建该类的实例进行操作,通过[createHidHostProfile()](./js-apis-bluetooth-hid.md#hidcreatehidhostprofile)方法构造此实例。 27 28### connect 29 30connect(deviceId: string): void 31 32连接设备的HidHost服务。 33 34**系统接口**:此接口为系统接口。 35 36**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 37 38**系统能力**:SystemCapability.Communication.Bluetooth.Core 39 40**参数:** 41 42| 参数名 | 类型 | 必填 | 说明 | 43| ------ | ------ | ---- | ------- | 44| deviceId | string | 是 | 远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | 45 46**错误码**: 47 48以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 49 50| 错误码ID | 错误信息 | 51| -------- | ---------------------------- | 52|201 | Permission denied. | 53|202 | Non-system applications are not allowed to use system APIs. | 54|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 55|801 | Capability not supported. | 56|2900001 | Service stopped. | 57|2900003 | Bluetooth disabled. | 58|2900004 | Profile not supported. | 59|2900099 | Operation failed. | 60 61**示例:** 62 63```js 64import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 65try { 66 let hidHostProfile = hid.createHidHostProfile(); 67 hidHostProfile.connect('XX:XX:XX:XX:XX:XX'); 68} catch (err) { 69 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 70} 71``` 72 73 74### disconnect 75 76disconnect(deviceId: string): void 77 78断开连接设备的HidHost服务。 79 80**系统接口**:此接口为系统接口。 81 82**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 83 84**系统能力**:SystemCapability.Communication.Bluetooth.Core 85 86**参数:** 87 88| 参数名 | 类型 | 必填 | 说明 | 89| ------ | ------ | ---- | ------- | 90| deviceId | string | 是 | 远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | 91 92**错误码**: 93 94以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 95 96| 错误码ID | 错误信息 | 97| -------- | ---------------------------- | 98|201 | Permission denied. | 99|202 | Non-system applications are not allowed to use system APIs. | 100|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 101|801 | Capability not supported. | 102|2900001 | Service stopped. | 103|2900003 | Bluetooth disabled. | 104|2900004 | Profile not supported. | 105|2900099 | Operation failed. | 106 107**示例:** 108 109```js 110import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 111try { 112 let hidHostProfile = hid.createHidHostProfile(); 113 hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX'); 114} catch (err) { 115 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 116} 117```