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 '@kit.ConnectivityKit';
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|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**Example**
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
68Disconnects from a hands-free device.
69
70**System API**: This is a system API.
71
72**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
73
74**System capability**: SystemCapability.Communication.Bluetooth.Core
75
76**Parameters**
77
78| Name   | Type    | Mandatory  | Description     |
79| ------ | ------ | ---- | ------- |
80| deviceId | string | Yes   | Address of the remote device.|
81
82**Error codes**
83
84For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
85
86| ID| Error Message|
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**Example**
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```
108