1e41f4b71Sopenharmony_ci# @ohos.bluetoothManager (Bluetooth) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **Bluetooth** module provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci> - The APIs provided by this module are no longer maintained since API version 10. You are advised to use profile APIs of [@ohos.bluetooth.ble](js-apis-bluetooth-ble.md).
9e41f4b71Sopenharmony_ci> - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.bluetoothManager](js-apis-bluetoothManager.md).
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Modules to Import
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci```js
16e41f4b71Sopenharmony_ciimport bluetoothManager from '@ohos.bluetoothManager';
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci## bluetoothManager.cancelPairedDevice<sup>(deprecated)</sup><a name="cancelPairedDevice"></a>
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_cicancelPairedDevice(deviceId: string): void
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciCancels a paired remote device.
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci> **NOTE**<br>
27e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. Use [connection.cancelPairedDevice](js-apis-bluetooth-connection-sys.md#connectioncancelpaireddevice) instead.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**System API**: This is a system API.
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.Bluetooth.Core
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**Parameters**
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci| Name     | Type    | Mandatory  | Description                                   |
38e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------- |
39e41f4b71Sopenharmony_ci| deviceId | string | Yes   | Address of the remote device to cancel, for example, XX:XX:XX:XX:XX:XX.|
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci**Error codes**
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciFor details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci| ID| Error Message|
46e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
47e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
48e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
49e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
50e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
51e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
52e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
53e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci**Example**
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci```js
58e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
59e41f4b71Sopenharmony_citry {
60e41f4b71Sopenharmony_ci    bluetoothManager.cancelPairedDevice("XX:XX:XX:XX:XX:XX");
61e41f4b71Sopenharmony_ci} catch (err) {
62e41f4b71Sopenharmony_ci    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
63e41f4b71Sopenharmony_ci}
64e41f4b71Sopenharmony_ci```
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci### connect<a name="HidHost-connect"></a>
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ciconnect(device: string): void
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ciConnects to the HidHost service of a device.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci> **NOTE**<br>
74e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. Use [hid.HidHostProfile#connect](js-apis-bluetooth-hid-sys.md#connect) instead.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**System API**: This is a system API.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.Bluetooth.Core
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Parameters**
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci| Name   | Type    | Mandatory  | Description     |
85e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
86e41f4b71Sopenharmony_ci| device | string | Yes   | Address of the target device.|
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Error codes**
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ciFor details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| ID| Error Message|
93e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
94e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
95e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
96e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
97e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
98e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
99e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
100e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
101e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**Example**
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci```js
106e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
107e41f4b71Sopenharmony_citry {
108e41f4b71Sopenharmony_ci    let hidHostProfile: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
109e41f4b71Sopenharmony_ci    hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
110e41f4b71Sopenharmony_ci} catch (err) {
111e41f4b71Sopenharmony_ci    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
112e41f4b71Sopenharmony_ci}
113e41f4b71Sopenharmony_ci```
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci### disconnect<sup>(deprecated)</sup><a name="HidHost-disconnect"></a>
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_cidisconnect(device: string): void
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ciDisconnects from the HidHost service of a device.
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci> **NOTE**<br>
123e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. Use [hid.HidHostProfile#disconnect](js-apis-bluetooth-hid-sys.md#disconnect) instead.
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci**System API**: This is a system API.
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.Bluetooth.Core
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**Parameters**
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci| Name   | Type    | Mandatory  | Description     |
134e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
135e41f4b71Sopenharmony_ci| device | string | Yes   | Address of the target device.|
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**Error codes**
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ciFor details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci| ID| Error Message|
142e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
143e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
144e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
145e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
146e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
147e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
148e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
149e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
150e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**Example**
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci```js
155e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
156e41f4b71Sopenharmony_citry {
157e41f4b71Sopenharmony_ci    let hidHostProfile: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
158e41f4b71Sopenharmony_ci    hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
159e41f4b71Sopenharmony_ci} catch (err) {
160e41f4b71Sopenharmony_ci    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
161e41f4b71Sopenharmony_ci}
162e41f4b71Sopenharmony_ci```
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci### disconnect<sup>(deprecated)</sup><a name="PanP-disconnect"></a>
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_cidisconnect(device: string): void
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ciDisconnects from the Personal Area Network (PAN) service of a device.
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci> **NOTE**<br>
173e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. Use [pan.PanProfile#disconnect](js-apis-bluetooth-pan-sys.md#disconnect) instead.
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci**System API**: This is a system API.
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.USE_BLUETOOTH
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.Bluetooth.Core
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci**Parameters**
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci| Name   | Type    | Mandatory  | Description     |
184e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
185e41f4b71Sopenharmony_ci| device | string | Yes   | Address of the target device.|
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci**Error codes**
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ciFor details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci| ID| Error Message|
192e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
193e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
194e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
195e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
196e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
197e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
198e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
199e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
200e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci**Example**
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci```js
205e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
206e41f4b71Sopenharmony_citry {
207e41f4b71Sopenharmony_ci    let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
208e41f4b71Sopenharmony_ci    panProfile.disconnect('XX:XX:XX:XX:XX:XX');
209e41f4b71Sopenharmony_ci} catch (err) {
210e41f4b71Sopenharmony_ci    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
211e41f4b71Sopenharmony_ci}
212e41f4b71Sopenharmony_ci```
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ci### setTethering<sup>(deprecated)</sup><a name="setTethering"></a>
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_cisetTethering(enable: boolean): void
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ciSets tethering.
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci> **NOTE**<br>
221e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. The substitute API is available only for system applications.
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci**System API**: This is a system API.
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.Bluetooth.Core
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci**Parameters**
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci| Name   | Type    | Mandatory  | Description     |
232e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
233e41f4b71Sopenharmony_ci| value | boolean | Yes   | Whether to set tethering over a Bluetooth PAN.|
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci**Error codes**
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ciFor details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci| ID| Error Message|
240e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
241e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
242e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
243e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                |
244e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
245e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
246e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
247e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
248e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ci**Example**
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci```js
253e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
254e41f4b71Sopenharmony_citry {
255e41f4b71Sopenharmony_ci    let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
256e41f4b71Sopenharmony_ci    panProfile.setTethering(true);
257e41f4b71Sopenharmony_ci} catch (err) {
258e41f4b71Sopenharmony_ci    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
259e41f4b71Sopenharmony_ci}
260e41f4b71Sopenharmony_ci```
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci### isTetheringOn<sup>(deprecated)</sup><a name="isTetheringOn"></a>
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ciisTetheringOn(): boolean
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ciObtains the network sharing status.
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci> **NOTE**<br>
270e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. Use [pan.PanProfile#isTetheringOn](js-apis-bluetooth-pan-sys.md#isTetheringOn) instead.
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci**System API**: This is a system API.
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.Bluetooth.Core
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci**Return value**
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci| Type     | Description                 |
279e41f4b71Sopenharmony_ci| --------------------- | --------------------------------- |
280e41f4b71Sopenharmony_ci| boolean | Returns **true** if tethering is available over a Bluetooth PAN; return **false** otherwise.|
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci**Error codes**
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ciFor details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci| ID| Error Message|
287e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
288e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
289e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci**Example**
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci```js
294e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
295e41f4b71Sopenharmony_citry {
296e41f4b71Sopenharmony_ci    let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
297e41f4b71Sopenharmony_ci    panProfile.isTetheringOn();
298e41f4b71Sopenharmony_ci} catch (err) {
299e41f4b71Sopenharmony_ci    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
300e41f4b71Sopenharmony_ci}
301e41f4b71Sopenharmony_ci```
302