• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bluetooth.hfp (Bluetooth HFP Module) (System API)
2
3The **hfp** module provides APIs for using the Bluetooth Hands-Free Profile (HFP).
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.bluetooth.hfp (Bluetooth HFP Module)](js-apis-bluetooth-hfp.md).
9
10
11## Modules to Import
12
13```js
14import hfp from '@ohos.bluetooth.hfp';
15```
16
17
18### connect
19
20connect(deviceId: string): void
21
22Connects to a hands-free device.
23
24**System API**: This is a system API.
25
26**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
27
28**System capability**: SystemCapability.Communication.Bluetooth.Core
29
30**Parameters**
31
32| Name   | Type    | Mandatory  | Description     |
33| ------ | ------ | ---- | ------- |
34| deviceId | string | Yes   | Address of the remote device.|
35
36**Error codes**
37
38For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
39
40| ID| Error Message|
41| -------- | ---------------------------- |
42|2900001 | Service stopped.                         |
43|2900003 | Bluetooth switch is off.                 |
44|2900004 | Profile is not supported.                |
45|2900099 | Operation failed.                        |
46
47**Example**
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
64Disconnects from a hands-free device.
65
66**System API**: This is a system API.
67
68**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
69
70**System capability**: SystemCapability.Communication.Bluetooth.Core
71
72**Parameters**
73
74| Name   | Type    | Mandatory  | Description     |
75| ------ | ------ | ---- | ------- |
76| deviceId | string | Yes   | Address of the remote device.|
77
78**Error codes**
79
80For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
81
82| ID| Error Message|
83| -------- | ---------------------------- |
84|2900001 | Service stopped.                         |
85|2900003 | Bluetooth switch is off.                 |
86|2900004 | Profile is not supported.                |
87|2900099 | Operation failed.                        |
88
89**Example**
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```
100