• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 '@ohos.bluetooth.hfp';
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|2900001 | Service stopped.                         |
43|2900003 | Bluetooth switch is off.                 |
44|2900004 | Profile is not supported.                |
45|2900099 | Operation failed.                        |
46
47**示例:**
48
49```js
50import { BusinessError } from '@ohos.base';
51try {
52    let hfpAg = hfp.createHfpAgProfile();
53    hfpAg.connect('XX:XX:XX:XX:XX:XX');
54} catch (err) {
55    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
56}
57```
58
59
60### disconnect
61
62disconnect(deviceId: string): void
63
64断开连接设备的HFP服务。
65
66**系统接口**:此接口为系统接口。
67
68**需要权限**:ohos.permission.ACCESS_BLUETOOTH
69
70**系统能力**:SystemCapability.Communication.Bluetooth.Core71
72**参数:**
73
74| 参数名    | 类型     | 必填   | 说明      |
75| ------ | ------ | ---- | ------- |
76| deviceId | string | 是    | 远端设备地址。 |
77
78**错误码**:
79
80以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
81
82| 错误码ID | 错误信息 |
83| -------- | ---------------------------- |
84|2900001 | Service stopped.                         |
85|2900003 | Bluetooth switch is off.                 |
86|2900004 | Profile is not supported.                |
87|2900099 | Operation failed.                        |
88
89**示例:**
90
91```js
92import { BusinessError } from '@ohos.base';
93try {
94    let hfpAg = hfp.createHfpAgProfile();
95    hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
96} catch (err) {
97    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
98}
99```