• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 '@ohos.bluetooth.hid';
15```
16
17## HidHostProfile
18
19使用HidHostProfile方法之前需要创建该类的实例进行操作,通过createHidHostProfile()方法构造此实例。
20
21### connect
22
23connect(deviceId: string): void
24
25连接设备的HidHost服务。
26
27**系统接口**:此接口为系统接口。
28
29**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
30
31**系统能力**:SystemCapability.Communication.Bluetooth.Core32
33**参数:**
34
35| 参数名    | 类型     | 必填   | 说明      |
36| ------ | ------ | ---- | ------- |
37| deviceId | string | 是    | 远端设备地址。 |
38
39**错误码**:
40
41以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
42
43| 错误码ID | 错误信息 |
44| -------- | ---------------------------- |
45|2900001 | Service stopped.                         |
46|2900003 | Bluetooth switch is off.                 |
47|2900004 | Profile is not supported.                |
48|2900099 | Operation failed.                        |
49
50**示例:**
51
52```js
53import { BusinessError } from '@ohos.base';
54try {
55    let hidHostProfile = hid.createHidHostProfile();
56    hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
57} catch (err) {
58    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
59}
60```
61
62
63### disconnect
64
65disconnect(deviceId: string): void
66
67断开连接设备的HidHost服务。
68
69**系统接口**:此接口为系统接口。
70
71**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
72
73**系统能力**:SystemCapability.Communication.Bluetooth.Core74
75**参数:**
76
77| 参数名    | 类型     | 必填   | 说明      |
78| ------ | ------ | ---- | ------- |
79| deviceId | string | 是    | 远端设备地址。 |
80
81**错误码**:
82
83以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
84
85| 错误码ID | 错误信息 |
86| -------- | ---------------------------- |
87|2900001 | Service stopped.                         |
88|2900003 | Bluetooth switch is off.                 |
89|2900004 | Profile is not supported.                |
90|2900099 | Operation failed.                        |
91
92**示例:**
93
94```js
95import { BusinessError } from '@ohos.base';
96try {
97    let hidHostProfile = hid.createHidHostProfile();
98    hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
99} catch (err) {
100    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
101}
102```