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