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