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