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