• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bluetoothManager (Bluetooth)
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
10
11
12## Modules to Import
13
14```js
15import bluetoothManager from '@ohos.bluetoothManager';
16import { BusinessError } from '@ohos.base';
17```
18
19
20## bluetoothManager.enableBluetooth<sup>(deprecated)</sup><a name="enableBluetooth"></a>
21
22enableBluetooth(): void
23
24Enables Bluetooth.
25
26> **NOTE**<br>
27> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.enableBluetooth](js-apis-bluetooth-access.md#accessenablebluetooth).
28
29**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
30
31**System capability**: SystemCapability.Communication.Bluetooth.Core
32
33**Error codes**
34
35For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
36
37| ID| Error Message|
38| -------- | ---------------------------- |
39|2900001 | Service stopped.                         |
40|2900099 | Operation failed.                        |
41
42**Example**
43
44```js
45try {
46    bluetoothManager.enableBluetooth();
47} catch (err) {
48    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
49}
50```
51
52
53## bluetoothManager.disableBluetooth<sup>(deprecated)</sup><a name="disableBluetooth"></a>
54
55disableBluetooth(): void
56
57Disables Bluetooth.
58
59> **NOTE**<br>
60> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.disableBluetooth](js-apis-bluetooth-access.md#accessdisablebluetooth).
61
62**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
63
64**System capability**: SystemCapability.Communication.Bluetooth.Core
65
66**Error codes**
67
68For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
69
70| ID| Error Message|
71| -------- | ---------------------------- |
72|2900001 | Service stopped.                         |
73|2900099 | Operation failed.                        |
74
75**Example**
76
77```js
78try {
79    bluetoothManager.disableBluetooth();
80} catch (err) {
81    console.error("errCode:" + (err as BusinessError).code + ", errMessage:" + (err as BusinessError).message);
82}
83```
84
85
86## bluetoothManager.getLocalName<sup>(deprecated)</sup><a name="getLocalName"></a>
87
88getLocalName(): string
89
90Obtains the name of the local Bluetooth device.
91
92> **NOTE**<br>
93> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getLocalName](js-apis-bluetooth-connection.md#connectiongetlocalname).
94
95**Required permissions**: ohos.permission.USE_BLUETOOTH
96
97**System capability**: SystemCapability.Communication.Bluetooth.Core
98
99**Return value**
100
101| Type    | Description       |
102| ------ | --------- |
103| string | Name of the local Bluetooth device obtained.|
104
105**Error codes**
106
107For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
108
109| ID| Error Message|
110| -------- | ---------------------------- |
111|2900001 | Service stopped.                         |
112|2900099 | Operation failed.                        |
113
114**Example**
115
116```js
117try {
118    let localName: string = bluetoothManager.getLocalName();
119} catch (err) {
120    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
121}
122```
123
124
125## bluetoothManager.getState<sup>(deprecated)</sup>
126
127getState(): BluetoothState
128
129Obtains the Bluetooth state.
130
131> **NOTE**<br>
132> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.getState](js-apis-bluetooth-access.md#accessgetstate).
133
134**Required permissions**: ohos.permission.USE_BLUETOOTH
135
136**System capability**: SystemCapability.Communication.Bluetooth.Core
137
138**Return value**
139
140| Type                               | Description       |
141| --------------------------------- | --------- |
142| [BluetoothState](#bluetoothstate) | Bluetooth state obtained.|
143
144**Error codes**
145
146For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
147
148| ID| Error Message|
149| -------- | ---------------------------- |
150|2900001 | Service stopped.                         |
151|2900099 | Operation failed.                        |
152
153**Example**
154
155```js
156try {
157    let state: bluetoothManager.BluetoothState = bluetoothManager.getState();
158} catch (err) {
159    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
160}
161```
162
163
164## bluetoothManager.getBtConnectionState<sup>(deprecated)</sup>
165
166getBtConnectionState(): ProfileConnectionState
167
168Obtains the local profile connection status.
169
170> **NOTE**<br>
171> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getProfileConnectionState](js-apis-bluetooth-connection.md#connectiongetprofileconnectionstate).
172
173**Required permissions**: ohos.permission.USE_BLUETOOTH
174
175**System capability**: SystemCapability.Communication.Bluetooth.Core
176
177**Return value**
178
179| Type                                      | Description                 |
180| ---------------------------------------- | ------------------- |
181| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
182
183**Error codes**
184
185For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
186
187| ID| Error Message|
188| -------- | ---------------------------- |
189|2900001 | Service stopped.                         |
190|2900003 | Bluetooth switch is off.                 |
191|2900099 | Operation failed.                        |
192
193**Example**
194
195```js
196try {
197    let connectionState: bluetoothManager.ProfileConnectionState = bluetoothManager.getBtConnectionState();
198} catch (err) {
199    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
200}
201```
202
203
204## bluetoothManager.setLocalName<sup>(deprecated)</sup><a name="setLocalName"></a>
205
206setLocalName(name: string): void
207
208Sets the name of the local Bluetooth device.
209
210> **NOTE**<br>
211> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.setLocalName](js-apis-bluetooth-connection.md#connectionsetlocalname).
212
213**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
214
215**System capability**: SystemCapability.Communication.Bluetooth.Core
216
217**Parameters**
218
219| Name | Type    | Mandatory  | Description                   |
220| ---- | ------ | ---- | --------------------- |
221| name | string | Yes   | Bluetooth device name to set. It cannot exceed 248 bytes.|
222
223**Error codes**
224
225For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
226
227| ID| Error Message|
228| -------- | ---------------------------- |
229|2900001 | Service stopped.                         |
230|2900003 | Bluetooth switch is off.                 |
231|2900099 | Operation failed.                        |
232
233**Example**
234
235```js
236try {
237    bluetoothManager.setLocalName('device_name');
238} catch (err) {
239    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
240}
241```
242
243
244## bluetoothManager.pairDevice<sup>(deprecated)</sup>
245
246pairDevice(deviceId: string): void
247
248Initiates Bluetooth pairing.
249
250> **NOTE**<br>
251> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.pairDevice](js-apis-bluetooth-connection.md#connectionpairdevice).
252
253**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
254
255**System capability**: SystemCapability.Communication.Bluetooth.Core
256
257**Parameters**
258
259| Name     | Type    | Mandatory  | Description                                 |
260| -------- | ------ | ---- | ----------------------------------- |
261| deviceId | string | Yes   | Address of the remote device to pair, for example, XX:XX:XX:XX:XX:XX.|
262
263**Error codes**
264
265For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
266
267| ID| Error Message|
268| -------- | ---------------------------- |
269|2900001 | Service stopped.                         |
270|2900003 | Bluetooth switch is off.                 |
271|2900099 | Operation failed.                        |
272
273**Example**
274
275```js
276try {
277    // The address can be scanned.
278    bluetoothManager.pairDevice("XX:XX:XX:XX:XX:XX");
279} catch (err) {
280    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
281}
282```
283
284
285## bluetoothManager.getProfileConnectionState<sup>(deprecated)</sup><a name="getProfileConnectionState"></a>
286
287getProfileConnectionState(profileId: ProfileId): ProfileConnectionState
288
289Obtains the connection status of the specified profile.
290
291> **NOTE**<br>
292> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getProfileConnectionState](js-apis-bluetooth-connection.md#connectiongetprofileconnectionstate).
293
294**Required permissions**: ohos.permission.USE_BLUETOOTH
295
296**System capability**: SystemCapability.Communication.Bluetooth.Core
297
298**Parameters**
299
300| Name      | Type       | Mandatory  | Description                                   |
301| --------- | --------- | ---- | ------------------------------------- |
302| ProfileId | profileId | Yes   | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
303
304**Return value**
305
306| Type                                             | Description               |
307| ------------------------------------------------- | ------------------- |
308| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
309
310**Error codes**
311
312For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
313
314| ID| Error Message|
315| -------- | ---------------------------- |
316|2900001 | Service stopped.                         |
317|2900003 | Bluetooth switch is off.                 |
318|2900004 | Profile is not supported.                |
319|2900099 | Operation failed.                        |
320
321**Example**
322
323```js
324try {
325    let result: bluetoothManager.ProfileConnectionState = bluetoothManager.getProfileConnectionState(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE);
326} catch (err) {
327    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
328}
329```
330
331
332## bluetoothManager.cancelPairedDevice<sup>(deprecated)</sup><a name="cancelPairedDevice"></a>
333
334cancelPairedDevice(deviceId: string): void
335
336Cancels a paired remote device.
337
338> **NOTE**<br>
339> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.cancelPairedDevice](js-apis-bluetooth-connection.md#connectioncancelpaireddevice).
340
341**System API**: This is a system API.
342
343**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
344
345**System capability**: SystemCapability.Communication.Bluetooth.Core
346
347**Parameters**
348
349| Name     | Type    | Mandatory  | Description                                   |
350| -------- | ------ | ---- | ------------------------------------- |
351| deviceId | string | Yes   | Address of the remote device to cancel, for example, XX:XX:XX:XX:XX:XX.|
352
353**Error codes**
354
355For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
356
357| ID| Error Message|
358| -------- | ---------------------------- |
359|2900001 | Service stopped.                         |
360|2900003 | Bluetooth switch is off.                 |
361|2900099 | Operation failed.                        |
362
363**Example**
364
365```js
366try {
367    bluetoothManager.cancelPairedDevice("XX:XX:XX:XX:XX:XX");
368} catch (err) {
369    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
370}
371```
372
373
374## bluetoothManager.getRemoteDeviceName<sup>(deprecated)</sup><a name="getRemoteDeviceName"></a>
375
376getRemoteDeviceName(deviceId: string): string
377
378Obtains the name of the remote Bluetooth device.
379
380> **NOTE**<br>
381> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getRemoteDeviceName](js-apis-bluetooth-connection.md#connectiongetremotedevicename).
382
383**Required permissions**: ohos.permission.USE_BLUETOOTH
384
385**System capability**: SystemCapability.Communication.Bluetooth.Core
386
387**Parameters**
388
389| Name     | Type    | Mandatory  | Description                               |
390| -------- | ------ | ---- | --------------------------------- |
391| deviceId | string | Yes   | Address of the target remote device, for example, XX:XX:XX:XX:XX:XX.|
392
393**Return value**
394
395| Type    | Description           |
396| ------ | ------------- |
397| string | Device name (a string) obtained.|
398
399**Error codes**
400
401For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
402
403| ID| Error Message|
404| -------- | ---------------------------- |
405|2900001 | Service stopped.                         |
406|2900003 | Bluetooth switch is off.                 |
407|2900099 | Operation failed.                        |
408
409**Example**
410
411```js
412try {
413    let remoteDeviceName: string = bluetoothManager.getRemoteDeviceName("XX:XX:XX:XX:XX:XX");
414} catch (err) {
415    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
416}
417```
418
419
420## bluetoothManager.getRemoteDeviceClass<sup>(deprecated)</sup><a name="getRemoteDeviceClass"></a>
421
422getRemoteDeviceClass(deviceId: string): DeviceClass
423
424Obtains the class of the remote Bluetooth device.
425
426> **NOTE**<br>
427> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getRemoteDeviceClass](js-apis-bluetooth-connection.md#connectiongetremotedeviceclass).
428
429**Required permissions**: ohos.permission.USE_BLUETOOTH
430
431**System capability**: SystemCapability.Communication.Bluetooth.Core
432
433**Parameters**
434
435| Name     | Type    | Mandatory  | Description                               |
436| -------- | ------ | ---- | --------------------------------- |
437| deviceId | string | Yes   | Address of the target remote device, for example, XX:XX:XX:XX:XX:XX.|
438
439**Return value**
440
441| Type                         | Description      |
442| --------------------------- | -------- |
443| [DeviceClass](#deviceclass) | Class of the remote device obtained.|
444
445**Error codes**
446
447For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
448
449| ID| Error Message|
450| -------- | ---------------------------- |
451|2900001 | Service stopped.                         |
452|2900003 | Bluetooth switch is off.                 |
453|2900099 | Operation failed.                        |
454
455**Example**
456
457```js
458try {
459    let remoteDeviceClass: bluetoothManager.DeviceClass  = bluetoothManager.getRemoteDeviceClass("XX:XX:XX:XX:XX:XX");
460} catch (err) {
461    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
462}
463```
464
465
466## bluetoothManager.getPairedDevices<sup>(deprecated)</sup><a name="getPairedDevices"></a>
467
468getPairedDevices(): Array&lt;string&gt;
469
470Obtains the paired devices.
471
472> **NOTE**<br>
473> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getPairedDevices](js-apis-bluetooth-connection.md#connectiongetpaireddevices).
474
475**Required permissions**: ohos.permission.USE_BLUETOOTH
476
477**System capability**: SystemCapability.Communication.Bluetooth.Core
478
479**Return value**
480
481| Type                 | Description           |
482| ------------------- | ------------- |
483| Array&lt;string&gt; | Addresses of the paired Bluetooth devices.|
484
485**Error codes**
486
487For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
488
489| ID| Error Message|
490| -------- | ---------------------------- |
491|2900001 | Service stopped.                         |
492|2900003 | Bluetooth switch is off.                 |
493|2900099 | Operation failed.                        |
494
495**Example**
496
497```js
498try {
499    let devices: Array<string> = bluetoothManager.getPairedDevices();
500} catch (err) {
501    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
502}
503```
504
505
506## bluetoothManager.setBluetoothScanMode<sup>(deprecated)</sup><a name="setBluetoothScanMode"></a>
507
508setBluetoothScanMode(mode: ScanMode, duration: number): void
509
510Sets the Bluetooth scan mode so that the device can be discovered by a remote device.
511
512> **NOTE**<br>
513> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.setBluetoothScanMode](js-apis-bluetooth-connection.md#connectionsetbluetoothscanmode).
514
515**Required permissions**: ohos.permission.USE_BLUETOOTH
516
517**System capability**: SystemCapability.Communication.Bluetooth.Core
518
519**Parameters**
520
521| Name     | Type                   | Mandatory  | Description                          |
522| -------- | --------------------- | ---- | ---------------------------- |
523| mode     | [ScanMode](#scanmode) | Yes   | Bluetooth scan mode to set.                     |
524| duration | number                | Yes   | Duration (in ms) in which the device can be discovered. The value **0** indicates unlimited time.|
525
526**Error codes**
527
528For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
529
530| ID| Error Message|
531| -------- | ---------------------------- |
532|2900001 | Service stopped.                         |
533|2900003 | Bluetooth switch is off.                 |
534|2900099 | Operation failed.                        |
535
536**Example**
537
538```js
539try {
540    // The device can be discovered and connected only when the discoverable and connectable mode is used.
541    bluetoothManager.setBluetoothScanMode(bluetoothManager.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100);
542} catch (err) {
543    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
544}
545```
546
547
548## bluetoothManager.getBluetoothScanMode<sup>(deprecated)</sup><a name="getBluetoothScanMode"></a>
549
550getBluetoothScanMode(): ScanMode
551
552Obtains the Bluetooth scan mode.
553
554> **NOTE**<br>
555> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.getBluetoothScanMode](js-apis-bluetooth-connection.md#connectiongetbluetoothscanmode).
556
557**Required permissions**: ohos.permission.USE_BLUETOOTH
558
559**System capability**: SystemCapability.Communication.Bluetooth.Core
560
561**Return value**
562
563| Type                   | Description     |
564| --------------------- | ------- |
565| [ScanMode](#scanmode) | Bluetooth scan mode to set.|
566
567**Error codes**
568
569For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
570
571| ID| Error Message|
572| -------- | ---------------------------- |
573|2900001 | Service stopped.                         |
574|2900003 | Bluetooth switch is off.                 |
575|2900099 | Operation failed.                        |
576
577**Example**
578
579```js
580try {
581    let scanMode: bluetoothManager.ScanMode = bluetoothManager.getBluetoothScanMode();
582} catch (err) {
583    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
584}
585```
586
587
588## bluetoothManager.startBluetoothDiscovery<sup>(deprecated)</sup><a name="startBluetoothDiscovery"></a>
589
590startBluetoothDiscovery(): void
591
592Starts Bluetooth scan to discover remote devices.
593
594> **NOTE**<br>
595> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.startBluetoothDiscovery](js-apis-bluetooth-connection.md#connectionstartbluetoothdiscovery).
596
597**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH and ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
598
599**System capability**: SystemCapability.Communication.Bluetooth.Core
600
601**Error codes**
602
603For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
604
605| ID| Error Message|
606| -------- | ---------------------------- |
607|2900001 | Service stopped.                         |
608|2900003 | Bluetooth switch is off.                 |
609|2900099 | Operation failed.                        |
610
611**Example**
612
613```js
614let deviceId: Array<string>;
615function onReceiveEvent(data: Array<string>) {
616    deviceId = data;
617}
618try {
619    bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
620    bluetoothManager.startBluetoothDiscovery();
621} catch (err) {
622    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
623}
624```
625
626
627## bluetoothManager.stopBluetoothDiscovery<sup>(deprecated)</sup><a name="stopBluetoothDiscovery"></a>
628
629stopBluetoothDiscovery(): void
630
631Stops Bluetooth scan.
632
633> **NOTE**<br>
634> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.stopBluetoothDiscovery](js-apis-bluetooth-connection.md#connectionstopbluetoothdiscovery).
635
636**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
637
638**System capability**: SystemCapability.Communication.Bluetooth.Core
639
640**Error codes**
641
642For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
643
644| ID| Error Message|
645| -------- | ---------------------------- |
646|2900001 | Service stopped.                         |
647|2900003 | Bluetooth switch is off.                 |
648|2900099 | Operation failed.                        |
649
650**Example**
651
652```js
653try {
654    bluetoothManager.stopBluetoothDiscovery();
655} catch (err) {
656    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
657}
658```
659
660
661## bluetoothManager.setDevicePairingConfirmation<sup>(deprecated)</sup><a name="setDevicePairingConfirmation"></a>
662
663setDevicePairingConfirmation(device: string, accept: boolean): void
664
665Sets the device pairing confirmation.
666
667> **NOTE**<br>
668> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.setDevicePairingConfirmation](js-apis-bluetooth-connection.md#connectionsetdevicepairingconfirmation).
669
670**Required permissions**: ohos.permission.MANAGE_BLUETOOTH
671
672**System capability**: SystemCapability.Communication.Bluetooth.Core
673
674**Parameters**
675
676| Name   | Type     | Mandatory  | Description                              |
677| ------ | ------- | ---- | -------------------------------- |
678| device | string  | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
679| accept | boolean | Yes   | Whether to accept the pairing request. The value **true** means to accept the pairing request, and the value **false** means the opposite.       |
680
681**Error codes**
682
683For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
684
685| ID| Error Message|
686| -------- | ---------------------------- |
687|2900001 | Service stopped.                         |
688|2900003 | Bluetooth switch is off.                 |
689|2900099 | Operation failed.                        |
690
691**Example**
692
693```js
694// Subscribe to the pinRequired event and configure the pairing confirmation after receiving a pairing request from the remote device.
695function onReceivePinRequiredEvent(data: bluetoothManager.PinRequiredParam) { // data is the input parameter for the pairing request.
696    console.info('pin required  = '+ JSON.stringify(data));
697    bluetoothManager.setDevicePairingConfirmation(data.deviceId, true);
698}
699try {
700    bluetoothManager.on("pinRequired", onReceivePinRequiredEvent);
701} catch (err) {
702    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
703}
704```
705
706
707## bluetoothManager.on('bluetoothDeviceFind')<sup>(deprecated)</sup>
708
709on(type: "bluetoothDeviceFind", callback: Callback&lt;Array&lt;string&gt;&gt;): void
710
711Subscribes to the Bluetooth device discovery events.
712
713> **NOTE**<br>
714> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.on('bluetoothDeviceFind')](js-apis-bluetooth-connection.md#connectiononbluetoothdevicefind).
715
716**Required permissions**: ohos.permission.USE_BLUETOOTH
717
718**System capability**: SystemCapability.Communication.Bluetooth.Core
719
720**Parameters**
721
722| Name     | Type                                 | Mandatory  | Description                                    |
723| -------- | ----------------------------------- | ---- | -------------------------------------- |
724| type     | string                              | Yes   | Event type. The value **bluetoothDeviceFind** indicates an event reported when a Bluetooth device is discovered.|
725| callback | Callback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the discovered devices. You need to implement this callback.   |
726
727**Error codes**
728
729For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
730
731| ID| Error Message|
732| -------- | ---------------------------- |
733|2900099 | Operation failed.                        |
734
735**Example**
736
737```js
738function onReceiveEvent(data: Array<string>) { // data is an array of Bluetooth device addresses.
739    console.info('bluetooth device find = '+ JSON.stringify(data));
740}
741try {
742    bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
743} catch (err) {
744    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
745}
746```
747
748
749## bluetoothManager.off('bluetoothDeviceFind')<sup>(deprecated)</sup>
750
751off(type: "bluetoothDeviceFind", callback?: Callback&lt;Array&lt;string&gt;&gt;): void
752
753Unsubscribes from the Bluetooth device discovery events.
754
755> **NOTE**<br>
756> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.off('bluetoothDeviceFind')](js-apis-bluetooth-connection.md#connectionoffbluetoothdevicefind).
757
758**Required permissions**: ohos.permission.USE_BLUETOOTH
759
760**System capability**: SystemCapability.Communication.Bluetooth.Core
761
762**Parameters**
763
764| Name     | Type                                 | Mandatory  | Description                                      |
765| -------- | ----------------------------------- | ---- | ---------------------------------------- |
766| type     | string                              | Yes   | Event type. The value **bluetoothDeviceFind** indicates an event reported when a Bluetooth device is discovered.  |
767| callback | Callback&lt;Array&lt;string&gt;&gt; | No   | Callback for the **bluetoothDeviceFind** event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
768
769**Error codes**
770
771For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
772
773| ID| Error Message|
774| -------- | ---------------------------- |
775|2900099 | Operation failed.                        |
776
777**Example**
778
779```js
780function onReceiveEvent(data: Array<string>) {
781    console.info('bluetooth device find = '+ JSON.stringify(data));
782}
783try {
784    bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
785    bluetoothManager.off('bluetoothDeviceFind', onReceiveEvent);
786} catch (err) {
787    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
788}
789```
790
791
792## bluetoothManager.on('pinRequired')<sup>(deprecated)</sup>
793
794on(type: "pinRequired", callback: Callback&lt;PinRequiredParam&gt;): void
795
796Subscribes to the pairing request events of the remote Bluetooth device.
797
798> **NOTE**<br>
799> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.on('pinRequired')](js-apis-bluetooth-connection.md#connectiononpinrequired).
800
801**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
802
803**System capability**: SystemCapability.Communication.Bluetooth.Core
804
805**Parameters**
806
807| Name     | Type                                      | Mandatory  | Description                              |
808| -------- | ---------------------------------------- | ---- | -------------------------------- |
809| type     | string                                   | Yes   | Event type. The value **pinRequired** indicates a pairing request event.    |
810| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | Yes   | Callback invoked to return the pairing request. You need to implement this callback.|
811
812**Error codes**
813
814For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
815
816| ID| Error Message|
817| -------- | ---------------------------- |
818|2900099 | Operation failed.                        |
819
820**Example**
821
822```js
823function onReceiveEvent(data: bluetoothManager.PinRequiredParam) { // data is the pairing request parameter.
824    console.info('pin required = '+ JSON.stringify(data));
825}
826try {
827    bluetoothManager.on('pinRequired', onReceiveEvent);
828} catch (err) {
829    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
830}
831```
832
833
834## bluetoothManager.off('pinRequired')<sup>(deprecated)</sup>
835
836off(type: "pinRequired", callback?: Callback&lt;PinRequiredParam&gt;): void
837
838Unsubscribes from the pairing request events of the remote Bluetooth device.
839
840> **NOTE**<br>
841> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.off('pinRequired')](js-apis-bluetooth-connection.md#connectionoffpinrequired).
842
843**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
844
845**System capability**: SystemCapability.Communication.Bluetooth.Core
846
847**Parameters**
848
849| Name     | Type                                      | Mandatory  | Description                                      |
850| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
851| type     | string                                   | Yes   | Event type. The value **pinRequired** indicates a pairing request event.            |
852| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | No   | Callback for the Bluetooth pairing request event. The input parameter is the pairing request parameter. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
853
854**Error codes**
855
856For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
857
858| ID| Error Message|
859| -------- | ---------------------------- |
860|2900099 | Operation failed.                        |
861
862**Example**
863
864```js
865function onReceiveEvent(data: bluetoothManager.PinRequiredParam) {
866    console.info('pin required = '+ JSON.stringify(data));
867}
868try {
869    bluetoothManager.on('pinRequired', onReceiveEvent);
870    bluetoothManager.off('pinRequired', onReceiveEvent);
871} catch (err) {
872    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
873}
874```
875
876
877## bluetoothManager.on('bondStateChange')<sup>(deprecated)</sup>
878
879on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void
880
881Subscribes to the Bluetooth pairing state changes.
882
883> **NOTE**<br>
884> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.on('bondStateChange')](js-apis-bluetooth-connection.md#connectiononbondstatechange).
885
886**Required permissions**: ohos.permission.USE_BLUETOOTH
887
888**System capability**: SystemCapability.Communication.Bluetooth.Core
889
890**Parameters**
891
892| Name     | Type                                      | Mandatory  | Description                                  |
893| -------- | ---------------------------------------- | ---- | ------------------------------------ |
894| type     | string                                   | Yes   | Event type. The value **bondStateChange** indicates a Bluetooth pairing state change event.|
895| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | Yes   | Callback invoked to return the pairing state. You need to implement this callback.   |
896
897**Error codes**
898
899For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
900
901| ID| Error Message|
902| -------- | ---------------------------- |
903|2900099 | Operation failed.                        |
904
905**Example**
906
907```js
908function onReceiveEvent(data: bluetoothManager.BondStateParam) { // data, as the input parameter of the callback, indicates the pairing state.
909    console.info('pair state = '+ JSON.stringify(data));
910}
911try {
912    bluetoothManager.on('bondStateChange', onReceiveEvent);
913} catch (err) {
914    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
915}
916```
917
918
919## bluetoothManager.off('bondStateChange')<sup>(deprecated)</sup>
920
921off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void
922
923Unsubscribes from the Bluetooth pairing state changes.
924
925> **NOTE**<br>
926> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.off('bondStateChange')](js-apis-bluetooth-connection.md#connectionoffbondstatechange).
927
928**Required permissions**: ohos.permission.USE_BLUETOOTH
929
930**System capability**: SystemCapability.Communication.Bluetooth.Core
931
932**Parameters**
933
934| Name     | Type                                      | Mandatory  | Description                                      |
935| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
936| type     | string                                   | Yes   | Event type. The value **bondStateChange** indicates a Bluetooth pairing state change event.    |
937| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | No   | Callback for the change of the Bluetooth pairing state. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
938
939**Error codes**
940
941For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
942
943| ID| Error Message|
944| -------- | ---------------------------- |
945|2900099 | Operation failed.                        |
946
947**Example**
948
949```js
950function onReceiveEvent(data: bluetoothManager.BondStateParam) {
951    console.info('bond state = '+ JSON.stringify(data));
952}
953try {
954    bluetoothManager.on('bondStateChange', onReceiveEvent);
955    bluetoothManager.off('bondStateChange', onReceiveEvent);
956} catch (err) {
957    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
958}
959```
960
961
962## bluetoothManager.on('stateChange')<sup>(deprecated)</sup>
963
964on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void
965
966Subscribes to Bluetooth state events.
967
968> **NOTE**<br>
969> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.on('stateChange')](js-apis-bluetooth-access.md#accessonstatechange).
970
971**Required permissions**: ohos.permission.USE_BLUETOOTH
972
973**System capability**: SystemCapability.Communication.Bluetooth.Core
974
975**Parameters**
976
977| Name     | Type                                      | Mandatory  | Description                              |
978| -------- | ---------------------------------------- | ---- | -------------------------------- |
979| type     | string                                   | Yes   | Event type. The value **stateChange** indicates a Bluetooth connection state change event.  |
980| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | Yes   | Callback invoked to return the Bluetooth connection state. You need to implement this callback.|
981
982**Error codes**
983
984For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
985
986| ID| Error Message|
987| -------- | ---------------------------- |
988|2900099 | Operation failed.                        |
989
990**Example**
991
992```js
993function onReceiveEvent(data: bluetoothManager.BluetoothState) {
994    console.info('bluetooth state = '+ JSON.stringify(data));
995}
996try {
997    bluetoothManager.on('stateChange', onReceiveEvent);
998} catch (err) {
999    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1000}
1001```
1002
1003
1004## bluetoothManager.off('stateChange')<sup>(deprecated)</sup>
1005
1006off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void
1007
1008Unsubscribes from Bluetooth state events.
1009
1010> **NOTE**<br>
1011> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.off('stateChange')](js-apis-bluetooth-access.md#accessoffstatechange).
1012
1013**Required permissions**: ohos.permission.USE_BLUETOOTH
1014
1015**System capability**: SystemCapability.Communication.Bluetooth.Core
1016
1017**Parameters**
1018
1019| Name     | Type                                      | Mandatory  | Description                                      |
1020| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1021| type     | string                                   | Yes   | Event type. The value **stateChange** indicates a Bluetooth connection state change event.          |
1022| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | No   | Callback for the Bluetooth connection state change event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
1023
1024**Error codes**
1025
1026For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1027
1028| ID| Error Message|
1029| -------- | ---------------------------- |
1030|2900099 | Operation failed.                        |
1031
1032**Example**
1033
1034```js
1035function onReceiveEvent(data: bluetoothManager.BluetoothState) {
1036    console.info('bluetooth state = '+ JSON.stringify(data));
1037}
1038try {
1039    bluetoothManager.on('stateChange', onReceiveEvent);
1040    bluetoothManager.off('stateChange', onReceiveEvent);
1041} catch (err) {
1042    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1043}
1044```
1045
1046
1047## bluetoothManager.sppListen<sup>(deprecated)</sup><a name="sppListen"></a>
1048
1049sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
1050
1051Creates a server listening socket.
1052
1053> **NOTE**<br>
1054> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppListen](js-apis-bluetooth-socket.md#socketspplisten).
1055
1056**Required permissions**: ohos.permission.USE_BLUETOOTH
1057
1058**System capability**: SystemCapability.Communication.Bluetooth.Core
1059
1060**Parameters**
1061
1062| Name     | Type                         | Mandatory  | Description                     |
1063| -------- | --------------------------- | ---- | ----------------------- |
1064| name     | string                      | Yes   | Name of the service.                 |
1065| option   | [SppOption](#sppoption)     | Yes   | Serial port profile (SPP) listening configuration.             |
1066| callback | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the server socket ID.|
1067
1068**Error codes**
1069
1070For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1071
1072| ID| Error Message|
1073| -------- | ---------------------------- |
1074|2900001 | Service stopped.                         |
1075|2900003 | Bluetooth switch is off.                 |
1076|2900004 | Profile is not supported.                |
1077|2900099 | Operation failed.                        |
1078
1079**Example**
1080
1081```js
1082let serverNumber = -1;
1083function serverSocket(code: BusinessError, number: number) {
1084  console.log('bluetooth error code: ' + code.code);
1085  if (code.code == 0) {
1086    console.log('bluetooth serverSocket Number: ' + number);
1087    serverNumber = number;
1088  }
1089}
1090
1091let sppOption: bluetoothManager.SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
1092try {
1093    bluetoothManager.sppListen('server1', sppOption, serverSocket);
1094} catch (err) {
1095    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1096}
1097```
1098
1099
1100## bluetoothManager.sppAccept<sup>(deprecated)</sup><a name="sppAccept"></a>
1101
1102sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void
1103
1104Listens for a connection to be made to this socket from the client and accepts it.
1105
1106> **NOTE**<br>
1107> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppAccept](js-apis-bluetooth-socket.md#socketsppaccept).
1108
1109**System capability**: SystemCapability.Communication.Bluetooth.Core
1110
1111**Parameters**
1112
1113| Name         | Type                         | Mandatory  | Description                     |
1114| ------------ | --------------------------- | ---- | ----------------------- |
1115| serverSocket | number                      | Yes   | Server socket ID.          |
1116| callback     | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the client socket ID.|
1117
1118**Error codes**
1119
1120For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1121
1122| ID| Error Message|
1123| -------- | ---------------------------- |
1124|2900001 | Service stopped.                         |
1125|2900003 | Bluetooth switch is off.                 |
1126|2900004 | Profile is not supported.                |
1127|2900099 | Operation failed.                        |
1128
1129**Example**
1130
1131```js
1132let serverNumber = -1;
1133function serverSocket(code: BusinessError, number: number) {
1134  console.log('bluetooth error code: ' + code.code);
1135  if (code.code == 0) {
1136    console.log('bluetooth serverSocket Number: ' + number);
1137    serverNumber = number;
1138  }
1139}
1140let clientNumber = -1;
1141function acceptClientSocket(code: BusinessError, number: number) {
1142  console.log('bluetooth error code: ' + code.code);
1143  if (code.code == 0) {
1144    console.log('bluetooth clientSocket Number: ' + number);
1145    // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the server.
1146    clientNumber = number;
1147  }
1148}
1149try {
1150    bluetoothManager.sppAccept(serverNumber, acceptClientSocket);
1151} catch (err) {
1152    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1153}
1154```
1155
1156
1157## bluetoothManager.sppConnect<sup>(deprecated)</sup><a name="sppConnect"></a>
1158
1159sppConnect(device: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
1160
1161Initiates an SPP connection to a remote device from the client.
1162
1163> **NOTE**<br>
1164> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppConnect](js-apis-bluetooth-socket.md#socketsppconnect).
1165
1166**Required permissions**: ohos.permission.USE_BLUETOOTH
1167
1168**System capability**: SystemCapability.Communication.Bluetooth.Core
1169
1170**Parameters**
1171
1172| Name     | Type                         | Mandatory  | Description                            |
1173| -------- | --------------------------- | ---- | ------------------------------ |
1174| device   | string                      | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
1175| option   | [SppOption](#sppoption)     | Yes   | Configuration for connecting to the SPP client.                 |
1176| callback | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the client socket ID.       |
1177
1178**Error codes**
1179
1180For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1181
1182| ID| Error Message|
1183| -------- | ---------------------------- |
1184|2900001 | Service stopped.                         |
1185|2900003 | Bluetooth switch is off.                 |
1186|2900004 | Profile is not supported.                |
1187|2900099 | Operation failed.                        |
1188
1189**Example**
1190
1191```js
1192
1193let clientNumber = -1;
1194function clientSocket(code: BusinessError, number: number) {
1195  if (code.code != 0) {
1196    return;
1197  }
1198  console.log('bluetooth serverSocket Number: ' + number);
1199  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
1200  clientNumber = number;
1201}
1202let sppOption: bluetoothManager.SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
1203try {
1204    bluetoothManager.sppConnect('XX:XX:XX:XX:XX:XX', sppOption, clientSocket);
1205} catch (err) {
1206    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1207}
1208```
1209
1210
1211## bluetoothManager.sppCloseServerSocket<sup>(deprecated)</sup><a name="sppCloseServerSocket"></a>
1212
1213sppCloseServerSocket(socket: number): void
1214
1215Closes the listening socket of the server.
1216
1217> **NOTE**<br>
1218> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppCloseServerSocket](js-apis-bluetooth-socket.md#socketsppcloseserversocket).
1219
1220**System capability**: SystemCapability.Communication.Bluetooth.Core
1221
1222**Parameters**
1223
1224| Name   | Type    | Mandatory  | Description             |
1225| ------ | ------ | ---- | --------------- |
1226| socket | number | Yes   | ID of the listening socket on the server. The ID is obtained by **sppListen**.|
1227
1228**Error codes**
1229
1230For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1231
1232| ID| Error Message|
1233| -------- | ---------------------------- |
1234|2900001 | Service stopped.                         |
1235|2900099 | Operation failed.                        |
1236
1237**Example**
1238
1239```js
1240let serverNumber = -1;
1241function serverSocket(code: BusinessError, number: number) {
1242  console.log('bluetooth error code: ' + code.code);
1243  if (code.code == 0) {
1244    console.log('bluetooth serverSocket Number: ' + number);
1245    serverNumber = number;
1246  }
1247}
1248try {
1249    bluetoothManager.sppCloseServerSocket(serverNumber);
1250} catch (err) {
1251    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1252}
1253```
1254
1255
1256## bluetoothManager.sppCloseClientSocket<sup>(deprecated)</sup><a name="sppCloseClientSocket"></a>
1257
1258sppCloseClientSocket(socket: number): void
1259
1260Closes the client socket.
1261
1262> **NOTE**<br>
1263> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppCloseClientSocket](js-apis-bluetooth-socket.md#socketsppcloseclientsocket).
1264
1265**System capability**: SystemCapability.Communication.Bluetooth.Core
1266
1267**Parameters**
1268
1269| Name   | Type    | Mandatory  | Description           |
1270| ------ | ------ | ---- | ------------- |
1271| Name   | Type    | Mandatory  | Description           |
1272| socket | number | Yes   | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.|
1273
1274**Error codes**
1275
1276For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1277
1278| ID| Error Message|
1279| -------- | ---------------------------- |
1280|2900001 | Service stopped.                         |
1281|2900099 | Operation failed.                        |
1282
1283**Example**
1284
1285```js
1286let clientNumber = -1;
1287function clientSocket(code: BusinessError, number: number) {
1288  if (code.code != 0) {
1289    return;
1290  }
1291  console.log('bluetooth serverSocket Number: ' + number);
1292  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
1293  clientNumber = number;
1294}
1295try {
1296    bluetoothManager.sppCloseClientSocket(clientNumber);
1297} catch (err) {
1298    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1299}
1300```
1301
1302
1303## bluetoothManager.sppWrite<sup>(deprecated)</sup><a name="sppWrite"></a>
1304
1305sppWrite(clientSocket: number, data: ArrayBuffer): void
1306
1307Writes data to the remote device through the socket.
1308
1309> **NOTE**<br>
1310> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.sppWrite](js-apis-bluetooth-socket.md#socketsppwrite).
1311
1312**System capability**: SystemCapability.Communication.Bluetooth.Core
1313
1314**Parameters**
1315
1316| Name         | Type         | Mandatory  | Description           |
1317| ------------ | ----------- | ---- | ------------- |
1318| clientSocket | number      | Yes   | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.|
1319| data         | ArrayBuffer | Yes   | Data to write.       |
1320
1321**Error codes**
1322
1323For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1324
1325| ID| Error Message|
1326| -------- | ---------------------------- |
1327|2901054 | IO error.                                |
1328|2900099 | Operation failed.                        |
1329
1330**Example**
1331
1332```js
1333let clientNumber = -1;
1334function clientSocket(code: BusinessError, number: number) {
1335  if (code.code != 0) {
1336    return;
1337  }
1338  console.log('bluetooth serverSocket Number: ' + number);
1339  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
1340  clientNumber = number;
1341}
1342let arrayBuffer = new ArrayBuffer(8);
1343let data = new Uint8Array(arrayBuffer);
1344data[0] = 123;
1345try {
1346    bluetoothManager.sppWrite(clientNumber, arrayBuffer);
1347} catch (err) {
1348    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1349}
1350```
1351
1352
1353## bluetoothManager.on('sppRead')<sup>(deprecated)</sup>
1354
1355on(type: "sppRead", clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void
1356
1357Subscribes to the SPP read request events.
1358
1359> **NOTE**<br>
1360> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.on('sppRead')](js-apis-bluetooth-socket.md#socketonsppread).
1361
1362**System capability**: SystemCapability.Communication.Bluetooth.Core
1363
1364**Parameters**
1365
1366| Name         | Type                         | Mandatory  | Description                        |
1367| ------------ | --------------------------- | ---- | -------------------------- |
1368| type         | string                      | Yes   | Event type. The value **sppRead** indicates an SPP read request event.|
1369| clientSocket | number                      | Yes   | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.             |
1370| callback     | Callback&lt;ArrayBuffer&gt; | Yes   | Callback invoked to return the data read.         |
1371
1372**Error codes**
1373
1374For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1375
1376| ID| Error Message|
1377| -------- | ---------------------------- |
1378|2901054 | IO error.                                |
1379|2900099 | Operation failed.                        |
1380
1381**Example**
1382
1383```js
1384let clientNumber = -1;
1385function clientSocket(code: BusinessError, number: number) {
1386  if (code.code != 0) {
1387    return;
1388  }
1389  console.log('bluetooth serverSocket Number: ' + number);
1390  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
1391  clientNumber = number;
1392}
1393function dataRead(dataBuffer: ArrayBuffer) {
1394  let data = new Uint8Array(dataBuffer);
1395  console.log('bluetooth data is: ' + data[0]);
1396}
1397try {
1398    bluetoothManager.on('sppRead', clientNumber, dataRead);
1399} catch (err) {
1400    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1401}
1402```
1403
1404
1405## bluetoothManager.off('sppRead')<sup>(deprecated)</sup>
1406
1407off(type: "sppRead", clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void
1408
1409Unsubscribes from the SPP read request events.
1410
1411> **NOTE**<br>
1412> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.off('sppRead')](js-apis-bluetooth-socket.md#socketoffsppread).
1413
1414**System capability**: SystemCapability.Communication.Bluetooth.Core
1415
1416**Parameters**
1417
1418| Name         | Type                         | Mandatory  | Description                                      |
1419| ------------ | --------------------------- | ---- | ---------------------------------------- |
1420| type         | string                      | Yes   | Event type. The value **sppRead** indicates an SPP read request event.              |
1421| clientSocket | number                      | Yes   | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.                           |
1422| callback     | Callback&lt;ArrayBuffer&gt; | No   | Callback for the SPP read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
1423
1424**Example**
1425
1426```js
1427let clientNumber = -1;
1428function clientSocket(code: BusinessError, number: number) {
1429  if (code.code != 0) {
1430    return;
1431  }
1432  console.log('bluetooth serverSocket Number: ' + number);
1433  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
1434  clientNumber = number;
1435}
1436try {
1437    bluetoothManager.off('sppRead', clientNumber);
1438} catch (err) {
1439    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1440}
1441```
1442
1443## bluetoothManager.getProfileInstance<sup>(deprecated)</sup><a name="getProfileInstance"></a>
1444
1445getProfileInstance(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile | PanProfile
1446
1447Obtains a profile instance. API version 9 is added with **HidHostProfile** and **PanProfile**.
1448
1449**System capability**: SystemCapability.Communication.Bluetooth.Core
1450
1451**Parameters**
1452
1453| Name      | Type       | Mandatory  | Description                                   |
1454| --------- | --------- | ---- | ------------------------------------- |
1455| profileId | [ProfileId](#ProfileId) | Yes   | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
1456
1457**Return value**
1458
1459| Type                                                        | Description                                                        |
1460| ------------------------------------------------------------ | ------------------------------------------------------------ |
1461| [A2dpSourceProfile](#a2dpsourceprofile), [HandsFreeAudioGatewayProfile](#handsfreeaudiogatewayprofile), [HidHostProfile](#hidhostprofile), or [PanProfile](#panprofile)| Profile instance obtained, which can be **A2dpSourceProfile**, **HandsFreeAudioGatewayProfile**, **HidHostProfile**, or **PanProfile**.|
1462
1463**Example**
1464
1465```js
1466try {
1467    let hidHost: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST);
1468} catch (err) {
1469    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1470}
1471```
1472
1473
1474## bluetoothManager.BLE
1475
1476### createGattServer<sup>(deprecated)</sup>
1477
1478createGattServer(): GattServer
1479
1480Creates a **GattServer** instance.
1481
1482> **NOTE**<br>
1483> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.createGattServer](js-apis-bluetooth-ble.md#blecreategattserver).
1484
1485**System capability**: SystemCapability.Communication.Bluetooth.Core
1486
1487**Return value**
1488
1489| Type                       | Description                                  |
1490| ------------------------- | ------------------------------------ |
1491| [GattServer](#gattserver) | **GattServer** instance created. Before using an API of this class, you must create a **GattSever** instance.|
1492
1493**Example**
1494
1495```js
1496let gattServer: bluetoothManager.GattServer  = bluetoothManager.BLE.createGattServer();
1497```
1498
1499
1500### createGattClientDevice<sup>(deprecated)</sup>
1501
1502createGattClientDevice(deviceId: string): GattClientDevice
1503
1504Creates a **GattClientDevice** instance.
1505
1506> **NOTE**<br>
1507> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.createGattClientDevice](js-apis-bluetooth-ble.md#blecreategattclientdevice).
1508
1509**System capability**: SystemCapability.Communication.Bluetooth.Core
1510
1511**Parameters**
1512
1513| Name     | Type    | Mandatory  | Description                                  |
1514| -------- | ------ | ---- | ------------------------------------ |
1515| deviceId | string | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
1516
1517**Return value**
1518
1519| Type                                   | Description                                  |
1520| ------------------------------------- | ------------------------------------ |
1521| [GattClientDevice](#gattclientdevice) | **GattClientDevice** instance created. Before using an API of the client, you must create a **GattClientDevice** instance.|
1522
1523**Example**
1524
1525```js
1526try {
1527    let device: bluetoothManager.GattClientDevice = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
1528} catch (err) {
1529    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1530}
1531```
1532
1533
1534### getConnectedBLEDevices<sup>(deprecated)</sup>
1535
1536getConnectedBLEDevices(): Array&lt;string&gt;
1537
1538Obtains the BLE devices connected to this device.
1539
1540> **NOTE**<br>
1541> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.getConnectedBLEDevices](js-apis-bluetooth-ble.md#blegetconnectedbledevices).
1542
1543**Required permissions**: ohos.permission.USE_BLUETOOTH
1544
1545**System capability**: SystemCapability.Communication.Bluetooth.Core
1546
1547**Return value**
1548
1549| Type                 | Description                 |
1550| ------------------- | ------------------- |
1551| Array&lt;string&gt; | Addresses of the BLE devices connected to this device.|
1552
1553**Error codes**
1554
1555For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1556
1557| ID| Error Message|
1558| -------- | ---------------------------- |
1559|2900001 | Service stopped.                         |
1560|2900003 | Bluetooth switch is off.                 |
1561|2900099 | Operation failed.                        |
1562
1563**Example**
1564
1565```js
1566try {
1567    let result: Array<string>  = bluetoothManager.BLE.getConnectedBLEDevices();
1568} catch (err) {
1569    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1570}
1571```
1572
1573
1574### startBLEScan<sup>(deprecated)</sup>
1575
1576startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
1577
1578Starts a BLE scan.
1579
1580> **NOTE**<br>
1581> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.startBLEScan](js-apis-bluetooth-ble.md#blestartblescan).
1582
1583**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH, ohos.permission.MANAGE_BLUETOOTH, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
1584
1585**System capability**: SystemCapability.Communication.Bluetooth.Core
1586
1587**Parameters**
1588
1589| Name    | Type                                    | Mandatory  | Description                                 |
1590| ------- | -------------------------------------- | ---- | ----------------------------------- |
1591| filters | Array&lt;[ScanFilter](#scanfilter)&gt; | Yes   | Criteria for filtering the scan result. Set this parameter to **null** if you do not want to filter the scan result.|
1592| options | [ScanOptions](#scanoptions)            | No   | Scan options.                    |
1593
1594**Error codes**
1595
1596For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1597
1598| ID| Error Message|
1599| -------- | ---------------------------- |
1600|2900001 | Service stopped.                         |
1601|2900003 | Bluetooth switch is off.                 |
1602|2900099 | Operation failed.                        |
1603
1604**Example**
1605
1606```js
1607function onReceiveEvent(data: Array<bluetoothManager.ScanResult>) {
1608    console.info('BLE scan device find result = '+ JSON.stringify(data));
1609}
1610try {
1611    bluetoothManager.BLE.on("BLEDeviceFind", onReceiveEvent);
1612    let scanfilter: bluetoothManager.ScanFilter = {
1613        deviceId:"XX:XX:XX:XX:XX:XX",
1614        name:"test",
1615        serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
1616    };
1617    let scanoptions: bluetoothManager.ScanOptions = {
1618        interval: 500,
1619        dutyMode: bluetoothManager.ScanDuty.SCAN_MODE_LOW_POWER,
1620        matchMode: bluetoothManager.MatchMode.MATCH_MODE_AGGRESSIVE,
1621    }
1622    bluetoothManager.BLE.startBLEScan([scanfilter], scanoptions);
1623} catch (err) {
1624    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1625}
1626```
1627
1628
1629### stopBLEScan<sup>(deprecated)</sup>
1630
1631stopBLEScan(): void
1632
1633Stops the BLE scan.
1634
1635> **NOTE**<br>
1636> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.startBLEScan](js-apis-bluetooth-ble.md#blestopblescan).
1637
1638**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1639
1640**System capability**: SystemCapability.Communication.Bluetooth.Core
1641
1642**Error codes**
1643
1644For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1645
1646| ID| Error Message|
1647| -------- | ---------------------------- |
1648|2900001 | Service stopped.                         |
1649|2900003 | Bluetooth switch is off.                 |
1650|2900099 | Operation failed.                        |
1651
1652**Example**
1653
1654```js
1655try {
1656    bluetoothManager.BLE.stopBLEScan();
1657} catch (err) {
1658    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1659}
1660```
1661
1662
1663### on('BLEDeviceFind')<sup>(deprecated)</sup>
1664
1665on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
1666
1667Subscribe to the BLE device discovery events.
1668
1669> **NOTE**<br>
1670> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.on('BLEDeviceFind')](js-apis-bluetooth-ble.md#bleonbledevicefind).
1671
1672**Required permissions**: ohos.permission.USE_BLUETOOTH
1673
1674**System capability**: SystemCapability.Communication.Bluetooth.Core
1675
1676**Parameters**
1677
1678| Name     | Type                                      | Mandatory  | Description                                 |
1679| -------- | ---------------------------------------- | ---- | ----------------------------------- |
1680| type     | string                                   | Yes   | Event type. The value **BLEDeviceFind** indicates an event reported when a BLE device is discovered.  |
1681| callback | Callback&lt;Array&lt;[ScanResult](#scanresult)&gt;&gt; | Yes   | Callback invoked to return the discovered devices. You need to implement this callback.|
1682
1683**Error codes**
1684
1685For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1686
1687| ID| Error Message|
1688| -------- | ---------------------------- |
1689|2900099 | Operation failed.                        |
1690
1691**Example**
1692
1693```js
1694function onReceiveEvent(data: Array<bluetoothManager.ScanResult>) {
1695    console.info('bluetooth device find = '+ JSON.stringify(data));
1696}
1697try {
1698    bluetoothManager.BLE.on('BLEDeviceFind', onReceiveEvent);
1699} catch (err) {
1700    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1701}
1702```
1703
1704
1705### off('BLEDeviceFind')<sup>(deprecated)</sup>
1706
1707off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
1708
1709Unsubscribes from the BLE device discovery events.
1710
1711> **NOTE**<br>
1712> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.off('BLEDeviceFind')](js-apis-bluetooth-ble.md#bleoffbledevicefind).
1713
1714**Required permissions**: ohos.permission.USE_BLUETOOTH
1715
1716**System capability**: SystemCapability.Communication.Bluetooth.Core
1717
1718**Parameters**
1719
1720| Name     | Type                                      | Mandatory  | Description                                      |
1721| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1722| type     | string                                   | Yes   | Event type. The value **BLEDeviceFind** indicates an event reported when a BLE device is discovered.       |
1723| callback | Callback&lt;Array&lt;[ScanResult](#scanresult)&gt;&gt; | No   | Callback for the **BLEDeviceFind** event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
1724
1725**Error codes**
1726
1727For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1728
1729| ID| Error Message|
1730| -------- | ---------------------------- |
1731|2900099 | Operation failed.                        |
1732
1733**Example**
1734
1735```js
1736function onReceiveEvent(data: Array<bluetoothManager.ScanResult>) {
1737    console.info('bluetooth device find = '+ JSON.stringify(data));
1738}
1739try {
1740    bluetoothManager.BLE.on('BLEDeviceFind', onReceiveEvent);
1741    bluetoothManager.BLE.off('BLEDeviceFind', onReceiveEvent);
1742} catch (err) {
1743    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1744}
1745```
1746
1747
1748## BaseProfile
1749
1750Provides the profile base class.
1751
1752
1753### getConnectionDevices<sup>(deprecated)</sup><a name="getConnectionDevices"></a>
1754
1755getConnectionDevices(): Array&lt;string&gt;
1756
1757Obtains the connected devices.
1758
1759> **NOTE**<br>
1760> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.getConnectedDevices](js-apis-bluetooth-baseProfile.md#baseprofilegetconnecteddevices).
1761
1762**Required permissions**: ohos.permission.USE_BLUETOOTH
1763
1764**System capability**: SystemCapability.Communication.Bluetooth.Core
1765
1766**Return value**
1767
1768| Type                 | Description           |
1769| ------------------- | ------------- |
1770| Array&lt;string&gt; | Addresses of the connected devices.|
1771
1772**Error codes**
1773
1774For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1775
1776| ID| Error Message|
1777| -------- | ---------------------------- |
1778|2900001 | Service stopped.                         |
1779|2900003 | Bluetooth switch is off.                 |
1780|2900004 | Profile is not supported.                |
1781|2900099 | Operation failed.                        |
1782
1783**Example**
1784
1785```js
1786try {
1787    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
1788    let retArray: Array<string> = a2dpSrc.getConnectionDevices();
1789} catch (err) {
1790    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1791}
1792```
1793
1794### getDeviceState<sup>(deprecated)</sup><a name="getDeviceState"></a>
1795
1796getDeviceState(device: string): ProfileConnectionState
1797
1798Obtains the connection state of the profile.
1799
1800> **NOTE**<br>
1801> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.getConnectionState](js-apis-bluetooth-baseProfile.md#baseprofilegetconnectionstate).
1802
1803**Required permissions**: ohos.permission.USE_BLUETOOTH
1804
1805**System capability**: SystemCapability.Communication.Bluetooth.Core
1806
1807**Parameters**
1808
1809| Name   | Type    | Mandatory  | Description     |
1810| ------ | ------ | ---- | ------- |
1811| device | string | Yes   | Address of the target device.|
1812
1813**Return value**
1814
1815| Type                                             | Description                   |
1816| ------------------------------------------------- | ----------------------- |
1817| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
1818
1819**Error codes**
1820
1821For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1822
1823| ID| Error Message|
1824| -------- | ---------------------------- |
1825|2900001 | Service stopped.                         |
1826|2900003 | Bluetooth switch is off.                 |
1827|2900004 | Profile is not supported.                |
1828|2900099 | Operation failed.                        |
1829
1830**Example**
1831
1832```js
1833try {
1834    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
1835    let ret: bluetoothManager.ProfileConnectionState = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX');
1836} catch (err) {
1837    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1838}
1839```
1840
1841
1842## A2dpSourceProfile
1843
1844Before using an API of **A2dpSourceProfile**, you need to create an instance of this class by using **getProfile()**.
1845
1846> **NOTE**<br>
1847> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.A2dpSourceProfile](js-apis-bluetooth-a2dp.md#a2dpsourceprofile).
1848
1849
1850### connect<sup>(deprecated)</sup><a name="a2dp-connect"></a>
1851
1852connect(device: string): void
1853
1854Sets up an Advanced Audio Distribution Profile (A2DP) connection.
1855
1856> **NOTE**<br>
1857> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.A2dpSourceProfile#connect](js-apis-bluetooth-a2dp.md#connect).
1858
1859**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1860
1861**System capability**: SystemCapability.Communication.Bluetooth.Core
1862
1863**Parameters**
1864
1865| Name   | Type    | Mandatory  | Description     |
1866| ------ | ------ | ---- | ------- |
1867| device | string | Yes   | Address of the target device.|
1868
1869**Error codes**
1870
1871For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1872
1873| ID| Error Message|
1874| -------- | ---------------------------- |
1875|2900001 | Service stopped.                         |
1876|2900003 | Bluetooth switch is off.                 |
1877|2900004 | Profile is not supported.                |
1878|2900099 | Operation failed.                        |
1879
1880**Example**
1881
1882```js
1883try {
1884    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
1885    a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
1886} catch (err) {
1887    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1888}
1889```
1890
1891
1892### disconnect<sup>(deprecated)</sup><a name="a2dp-disconnect"></a>
1893
1894disconnect(device: string): void
1895
1896Disconnects an A2DP connection.
1897
1898> **NOTE**<br>
1899> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.A2dpSourceProfile#disconnect](js-apis-bluetooth-a2dp.md#disconnect).
1900
1901**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1902
1903**System capability**: SystemCapability.Communication.Bluetooth.Core
1904
1905**Parameters**
1906
1907| Name   | Type    | Mandatory  | Description     |
1908| ------ | ------ | ---- | ------- |
1909| device | string | Yes   | Address of the target device.|
1910
1911**Error codes**
1912
1913For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1914
1915| ID| Error Message|
1916| -------- | ---------------------------- |
1917|2900001 | Service stopped.                         |
1918|2900003 | Bluetooth switch is off.                 |
1919|2900004 | Profile is not supported.                |
1920|2900099 | Operation failed.                        |
1921
1922**Example**
1923
1924```js
1925try {
1926    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
1927    a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
1928} catch (err) {
1929    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1930}
1931```
1932
1933
1934### on('connectionStateChange')<sup>(deprecated)</sup>
1935
1936on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
1937
1938Subscribes to the A2DP connection state changes.
1939
1940> **NOTE**<br>
1941> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange).
1942
1943**System capability**: SystemCapability.Communication.Bluetooth.Core
1944
1945**Parameters**
1946
1947| Name     | Type                                      | Mandatory  | Description                                      |
1948| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1949| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates a A2DP connection state change event.|
1950| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes   | Callback invoked to return the A2DP connection state change event.                              |
1951
1952**Return value**
1953
1954No value is returned.
1955
1956**Example**
1957
1958```js
1959function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
1960    console.info('a2dp state = '+ JSON.stringify(data));
1961}
1962let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
1963a2dpSrc.on('connectionStateChange', onReceiveEvent);
1964```
1965
1966
1967### off('connectionStateChange')<sup>(deprecated)</sup>
1968
1969off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
1970
1971Unsubscribes from the A2DP connection state changes.
1972
1973> **NOTE**<br>
1974> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange).
1975
1976**System capability**: SystemCapability.Communication.Bluetooth.Core
1977
1978**Parameters**
1979
1980| Name     | Type                                      | Mandatory  | Description                                      |
1981| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1982| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates a A2DP connection state change event.|
1983| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No   | Callback for the A2DP connection state change event.                              |
1984
1985**Return value**
1986
1987No value is returned.
1988
1989**Example**
1990
1991```js
1992function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
1993    console.info('a2dp state = '+ JSON.stringify(data));
1994}
1995let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
1996a2dpSrc.on('connectionStateChange', onReceiveEvent);
1997a2dpSrc.off('connectionStateChange', onReceiveEvent);
1998```
1999
2000
2001### getPlayingState<sup>(deprecated)</sup>
2002
2003getPlayingState(device: string): PlayingState
2004
2005Obtains the playing state of a device.
2006
2007> **NOTE**<br>
2008> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.A2dpSourceProfile#getPlayingState](js-apis-bluetooth-a2dp.md#getPlayingState).
2009
2010**System capability**: SystemCapability.Communication.Bluetooth.Core
2011
2012**Parameters**
2013
2014| Name   | Type    | Mandatory  | Description     |
2015| ------ | ------ | ---- | ------- |
2016| device | string | Yes   | Address of the target device.|
2017
2018**Return value**
2019
2020| Type                           | Description        |
2021| ----------------------------- | ---------- |
2022| [PlayingState](#PlayingState) | Playing state of the remote device obtained.|
2023
2024**Error codes**
2025
2026For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2027
2028| ID| Error Message|
2029| -------- | ---------------------------- |
2030|2900001 | Service stopped.                         |
2031|2900003 | Bluetooth switch is off.                 |
2032|2900004 | Profile is not supported.                |
2033|2900099 | Operation failed.                        |
2034
2035**Example**
2036
2037```js
2038try {
2039    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
2040    let state: bluetoothManager.PlayingState  = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
2041} catch (err) {
2042    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2043}
2044```
2045
2046
2047## HandsFreeAudioGatewayProfile<sup>(deprecated)</sup>
2048
2049Before using an API of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using **getProfile()**.
2050
2051> **NOTE**<br>
2052> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hfp.HandsFreeAudioGatewayProfile](js-apis-bluetooth-hfp.md#HandsFreeAudioGatewayProfile).
2053
2054
2055### connect<a name="hfp-connect"></a>
2056
2057connect(device: string): void
2058
2059Sets up a Hands-free Profile (HFP) connection of a device.
2060
2061> **NOTE**<br>
2062> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hfp.HandsFreeAudioGatewayProfile#connect](js-apis-bluetooth-hfp.md#connect).
2063
2064**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
2065
2066**System capability**: SystemCapability.Communication.Bluetooth.Core
2067
2068**Parameters**
2069
2070| Name   | Type    | Mandatory  | Description     |
2071| ------ | ------ | ---- | ------- |
2072| device | string | Yes   | Address of the target device.|
2073
2074**Error codes**
2075
2076For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2077
2078| ID| Error Message|
2079| -------- | ---------------------------- |
2080|2900001 | Service stopped.                         |
2081|2900003 | Bluetooth switch is off.                 |
2082|2900004 | Profile is not supported.                |
2083|2900099 | Operation failed.                        |
2084
2085**Example**
2086
2087```js
2088try {
2089    let hfpAg: bluetoothManager.HandsFreeAudioGatewayProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as bluetoothManager.HandsFreeAudioGatewayProfile;
2090    hfpAg.connect('XX:XX:XX:XX:XX:XX');
2091} catch (err) {
2092    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2093}
2094```
2095
2096
2097### disconnect<sup>(deprecated)</sup><a name="hfp-disconnect"></a>
2098
2099disconnect(device: string): void
2100
2101Disconnects the HFP connection of a device.
2102
2103> **NOTE**<br>
2104> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hfp.HandsFreeAudioGatewayProfile#disconnect](js-apis-bluetooth-hfp.md#disconnect).
2105
2106**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
2107
2108**System capability**: SystemCapability.Communication.Bluetooth.Core
2109
2110**Parameters**
2111
2112| Name   | Type    | Mandatory  | Description     |
2113| ------ | ------ | ---- | ------- |
2114| device | string | Yes   | Address of the target device.|
2115
2116**Error codes**
2117
2118For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2119
2120| ID| Error Message|
2121| -------- | ---------------------------- |
2122|2900001 | Service stopped.                         |
2123|2900003 | Bluetooth switch is off.                 |
2124|2900004 | Profile is not supported.                |
2125|2900099 | Operation failed.                        |
2126
2127**Example**
2128
2129```js
2130try {
2131    let hfpAg: bluetoothManager.HandsFreeAudioGatewayProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as bluetoothManager.HandsFreeAudioGatewayProfile;
2132    hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
2133} catch (err) {
2134    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2135}
2136```
2137
2138
2139### on('connectionStateChange')<sup>(deprecated)</sup>
2140
2141on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
2142
2143Subscribes to the HFP connection state changes.
2144
2145> **NOTE**<br>
2146> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange).
2147
2148**System capability**: SystemCapability.Communication.Bluetooth.Core
2149
2150**Parameters**
2151
2152| Name     | Type                                      | Mandatory  | Description                                      |
2153| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2154| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
2155| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes   | Callback invoked to return the HFP connection state change event.                              |
2156
2157**Example**
2158
2159```js
2160function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2161    console.info('hfp state = '+ JSON.stringify(data));
2162}
2163let hfpAg: bluetoothManager.HandsFreeAudioGatewayProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
2164  bluetoothManager.HandsFreeAudioGatewayProfile;
2165hfpAg.on('connectionStateChange', onReceiveEvent);
2166```
2167
2168
2169### off('connectionStateChange')<sup>(deprecated)</sup>
2170
2171off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
2172
2173Unsubscribes from the HFP connection state changes.
2174
2175> **NOTE**<br>
2176> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange).
2177
2178**System capability**: SystemCapability.Communication.Bluetooth.Core
2179
2180**Parameters**
2181
2182| Name     | Type                                      | Mandatory  | Description                                      |
2183| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2184| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
2185| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No   | Callback for the HFP connection state change event.                              |
2186
2187**Example**
2188
2189```js
2190function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2191    console.info('hfp state = '+ JSON.stringify(data));
2192}
2193let hfpAg: bluetoothManager.HandsFreeAudioGatewayProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
2194  bluetoothManager.HandsFreeAudioGatewayProfile;
2195hfpAg.on('connectionStateChange', onReceiveEvent);
2196hfpAg.off('connectionStateChange', onReceiveEvent);
2197```
2198
2199
2200## HidHostProfile<sup>(deprecated)</sup>
2201
2202Before using an API of **HidHostProfile**, you need to create an instance of this class by using **getProfile()**.
2203
2204
2205### connect<a name="HidHost-connect"></a>
2206
2207connect(device: string): void
2208
2209Connects to the HidHost service of a device.
2210
2211> **NOTE**<br>
2212> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hid.HidHostProfile#connect](js-apis-bluetooth-hid.md#connect).
2213
2214**System API**: This is a system API.
2215
2216**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
2217
2218**System capability**: SystemCapability.Communication.Bluetooth.Core
2219
2220**Parameters**
2221
2222| Name   | Type    | Mandatory  | Description     |
2223| ------ | ------ | ---- | ------- |
2224| device | string | Yes   | Address of the target device.|
2225
2226**Error codes**
2227
2228For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2229
2230| ID| Error Message|
2231| -------- | ---------------------------- |
2232|2900001 | Service stopped.                         |
2233|2900003 | Bluetooth switch is off.                 |
2234|2900004 | Profile is not supported.                |
2235|2900099 | Operation failed.                        |
2236
2237**Example**
2238
2239```js
2240try {
2241    let hidHostProfile: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
2242    hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
2243} catch (err) {
2244    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2245}
2246```
2247
2248
2249### disconnect<sup>(deprecated)</sup><a name="HidHost-disconnect"></a>
2250
2251disconnect(device: string): void
2252
2253Disconnects from the HidHost service of a device.
2254
2255> **NOTE**<br>
2256> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [hid.HidHostProfile#disconnect](js-apis-bluetooth-hid.md#disconnect).
2257
2258**System API**: This is a system API.
2259
2260**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
2261
2262**System capability**: SystemCapability.Communication.Bluetooth.Core
2263
2264**Parameters**
2265
2266| Name   | Type    | Mandatory  | Description     |
2267| ------ | ------ | ---- | ------- |
2268| device | string | Yes   | Address of the target device.|
2269
2270**Error codes**
2271
2272For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2273
2274| ID| Error Message|
2275| -------- | ---------------------------- |
2276|2900001 | Service stopped.                         |
2277|2900003 | Bluetooth switch is off.                 |
2278|2900004 | Profile is not supported.                |
2279|2900099 | Operation failed.                        |
2280
2281**Example**
2282
2283```js
2284try {
2285    let hidHostProfile: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
2286    hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
2287} catch (err) {
2288    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2289}
2290```
2291
2292
2293### on('connectionStateChange')<sup>(deprecated)</sup>
2294
2295on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
2296
2297Subscribes to the HidHost connection state changes.
2298
2299> **NOTE**<br>
2300> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange).
2301
2302**System capability**: SystemCapability.Communication.Bluetooth.Core
2303
2304**Parameters**
2305
2306| Name     | Type                                      | Mandatory  | Description                                      |
2307| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2308| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates a HidHost connection state change event. |
2309| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes   | Callback invoked to return the HidHost connection state change event.                |
2310
2311**Example**
2312
2313```js
2314function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2315    console.info('hidHost state = '+ JSON.stringify(data));
2316}
2317let hidHost: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
2318hidHost.on('connectionStateChange', onReceiveEvent);
2319```
2320
2321
2322### off('connectionStateChange')<sup>(deprecated)</sup>
2323
2324off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
2325
2326Unsubscribes from the HidHost connection state changes.
2327
2328> **NOTE**<br>
2329> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange).
2330
2331**System capability**: SystemCapability.Communication.Bluetooth.Core
2332
2333**Parameters**
2334
2335| Name  | Type                                                 | Mandatory| Description                                                     |
2336| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
2337| type     | string                                                | Yes  | Event type. The value **connectionStateChange** indicates a HidHost connection state change event. |
2338| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No  | Callback for the HidHost connection state change event.                            |
2339
2340**Example**
2341
2342```js
2343function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2344    console.info('hidHost state = '+ JSON.stringify(data));
2345}
2346let hidHost: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
2347hidHost.on('connectionStateChange', onReceiveEvent);
2348hidHost.off('connectionStateChange', onReceiveEvent);
2349```
2350
2351
2352## PanProfile
2353
2354Before using an API of **PanProfile**, you need to create an instance of this class by using **getProfile()**.
2355
2356> **NOTE**<br>
2357> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [pan.PanProfile](js-apis-bluetooth-pan.md#panprofile).
2358
2359
2360### disconnect<sup>(deprecated)</sup><a name="PanP-disconnect"></a>
2361
2362disconnect(device: string): void
2363
2364Disconnects from the Personal Area Network (PAN) service of a device.
2365
2366> **NOTE**<br>
2367> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [pan.PanProfile#disconnect](js-apis-bluetooth-pan.md#disconnect).
2368
2369**System API**: This is a system API.
2370
2371**Required permissions**: ohos.permission.USE_BLUETOOTH
2372
2373**System capability**: SystemCapability.Communication.Bluetooth.Core
2374
2375**Parameters**
2376
2377| Name   | Type    | Mandatory  | Description     |
2378| ------ | ------ | ---- | ------- |
2379| device | string | Yes   | Address of the target device.|
2380
2381**Error codes**
2382
2383For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2384
2385| ID| Error Message|
2386| -------- | ---------------------------- |
2387|2900001 | Service stopped.                         |
2388|2900003 | Bluetooth switch is off.                 |
2389|2900004 | Profile is not supported.                |
2390|2900099 | Operation failed.                        |
2391
2392**Example**
2393
2394```js
2395try {
2396    let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
2397    panProfile.disconnect('XX:XX:XX:XX:XX:XX');
2398} catch (err) {
2399    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2400}
2401```
2402
2403
2404### on('connectionStateChange')<sup>(deprecated)</sup>
2405
2406on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
2407
2408Subscribes to the PAN connection state changes.
2409
2410> **NOTE**<br>
2411> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange).
2412
2413**System capability**: SystemCapability.Communication.Bluetooth.Core
2414
2415**Parameters**
2416
2417| Name     | Type                                      | Mandatory  | Description                                      |
2418| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2419| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates a PAN connection state change event.|
2420| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes   | Callback invoked to return the PAN connection state change event.                              |
2421
2422**Example**
2423
2424```js
2425function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2426    console.info('pan state = '+ JSON.stringify(data));
2427}
2428let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
2429panProfile.on('connectionStateChange', onReceiveEvent);
2430```
2431
2432
2433### off('connectionStateChange')<sup>(deprecated)</sup>
2434
2435off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
2436
2437Unsubscribes from the PAN connection state changes.
2438
2439> **NOTE**<br>
2440> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange).
2441
2442**System capability**: SystemCapability.Communication.Bluetooth.Core
2443
2444**Parameters**
2445
2446| Name  | Type                                                 | Mandatory| Description                                                     |
2447| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
2448| type     | string                                                | Yes  | Event type. The value **connectionStateChange** indicates a PAN connection state change event.|
2449| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No  | Callback for the PAN connection state change event.                                     |
2450
2451**Example**
2452
2453```js
2454function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2455    console.info('pan state = '+ JSON.stringify(data));
2456}
2457let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
2458panProfile.on('connectionStateChange', onReceiveEvent);
2459panProfile.off('connectionStateChange', onReceiveEvent);
2460```
2461
2462
2463### setTethering<sup>(deprecated)</sup><a name="setTethering"></a>
2464
2465setTethering(enable: boolean): void
2466
2467Sets tethering.
2468
2469> **NOTE**<br>
2470> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [pan.PanProfile#setTethering](js-apis-bluetooth-pan.md#setTethering).
2471
2472**System API**: This is a system API.
2473
2474**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
2475
2476**System capability**: SystemCapability.Communication.Bluetooth.Core
2477
2478**Parameters**
2479
2480| Name   | Type    | Mandatory  | Description     |
2481| ------ | ------ | ---- | ------- |
2482| value | boolean | Yes   | Whether to set tethering over a Bluetooth PAN.|
2483
2484**Error codes**
2485
2486For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2487
2488| ID| Error Message|
2489| -------- | ---------------------------- |
2490|2900001 | Service stopped.                         |
2491|2900003 | Bluetooth switch is off.                 |
2492|2900004 | Profile is not supported.                |
2493|2900099 | Operation failed.                        |
2494
2495**Example**
2496
2497```js
2498try {
2499    let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
2500    panProfile.setTethering(true);
2501} catch (err) {
2502    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2503}
2504```
2505
2506
2507### isTetheringOn<sup>(deprecated)</sup><a name="isTetheringOn"></a>
2508
2509isTetheringOn(): boolean
2510
2511Obtains the network sharing status.
2512
2513> **NOTE**<br>
2514> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [pan.PanProfile#isTetheringOn](js-apis-bluetooth-pan.md#isTetheringOn).
2515
2516**System API**: This is a system API.
2517
2518**System capability**: SystemCapability.Communication.Bluetooth.Core
2519
2520**Return value**
2521
2522| Type     | Description                 |
2523| --------------------- | --------------------------------- |
2524| boolean | Returns **true** if tethering is available over a Bluetooth PAN; return **false** otherwise.|
2525
2526**Example**
2527
2528```js
2529try {
2530    let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
2531    panProfile.isTetheringOn();
2532} catch (err) {
2533    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2534}
2535```
2536
2537
2538## GattServer
2539
2540Implements the Generic Attribute Profile (GATT) server. Before using an API of this class, you need to create a **GattServer** instance using **createGattServer()**.
2541
2542> **NOTE**<br>
2543> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer](js-apis-bluetooth-ble.md#GattServer).
2544
2545
2546### startAdvertising<sup>(deprecated)</sup>
2547
2548startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void
2549
2550Starts BLE advertising.
2551
2552> **NOTE**<br>
2553> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.startAdvertising](js-apis-bluetooth-ble.md#blestartadvertising).
2554
2555**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
2556
2557**System capability**: SystemCapability.Communication.Bluetooth.Core
2558
2559**Parameters**
2560
2561| Name        | Type                                   | Mandatory  | Description            |
2562| ----------- | ------------------------------------- | ---- | -------------- |
2563| setting     | [AdvertiseSetting](#advertisesetting) | Yes   | Settings related to BLE advertising.   |
2564| advData     | [AdvertiseData](#advertisedata)       | Yes   | Content of the BLE advertisement packet.     |
2565| advResponse | [AdvertiseData](#advertisedata)       | No   | Response to the BLE scan request.|
2566
2567**Error codes**
2568
2569For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2570
2571| ID| Error Message|
2572| -------- | ---------------------------- |
2573|2900001 | Service stopped.                         |
2574|2900003 | Bluetooth switch is off.                 |
2575|2900099 | Operation failed.                        |
2576
2577**Example**
2578
2579```js
2580let manufactureValueBuffer = new Uint8Array(4);
2581manufactureValueBuffer[0] = 1;
2582manufactureValueBuffer[1] = 2;
2583manufactureValueBuffer[2] = 3;
2584manufactureValueBuffer[3] = 4;
2585
2586let serviceValueBuffer = new Uint8Array(4);
2587serviceValueBuffer[0] = 4;
2588serviceValueBuffer[1] = 6;
2589serviceValueBuffer[2] = 7;
2590serviceValueBuffer[3] = 8;
2591console.info('manufactureValueBuffer = '+ JSON.stringify(manufactureValueBuffer));
2592console.info('serviceValueBuffer = '+ JSON.stringify(serviceValueBuffer));
2593let gattServer = bluetoothManager.BLE.createGattServer();
2594try {
2595    let setting: bluetoothManager.AdvertiseSetting = {
2596        interval:150,
2597        txPower:0,
2598        connectable:true,
2599    };
2600    let manufactureDataUnit: bluetoothManager.ManufactureData = {
2601        manufactureId:4567,
2602        manufactureValue:manufactureValueBuffer.buffer
2603    };
2604    let serviceDataUnit: bluetoothManager.ServiceData = {
2605        serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
2606        serviceValue:serviceValueBuffer.buffer
2607    };
2608    let advData: bluetoothManager.AdvertiseData = {
2609        serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
2610        manufactureData:[manufactureDataUnit],
2611        serviceData:[serviceDataUnit],
2612    };
2613    let advResponse: bluetoothManager.AdvertiseData = {
2614        serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
2615        manufactureData:[manufactureDataUnit],
2616        serviceData:[serviceDataUnit],
2617    };
2618    gattServer.startAdvertising(setting, advData ,advResponse);
2619} catch (err) {
2620    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2621}
2622```
2623
2624
2625### stopAdvertising<sup>(deprecated)</sup>
2626
2627stopAdvertising(): void
2628
2629Stops BLE advertising.
2630
2631> **NOTE**<br>
2632> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.stopAdvertising](js-apis-bluetooth-ble.md#blestopadvertising).
2633
2634**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
2635
2636**System capability**: SystemCapability.Communication.Bluetooth.Core
2637
2638**Error codes**
2639
2640For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2641
2642| ID| Error Message|
2643| -------- | ---------------------------- |
2644|2900001 | Service stopped.                         |
2645|2900003 | Bluetooth switch is off.                 |
2646|2900099 | Operation failed.                        |
2647
2648**Example**
2649
2650```js
2651let server = bluetoothManager.BLE.createGattServer();
2652try {
2653    server.stopAdvertising();
2654} catch (err) {
2655    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2656}
2657```
2658
2659
2660### addService<sup>(deprecated)</sup>
2661
2662addService(service: GattService): void
2663
2664Adds a service to this GATT server.
2665
2666> **NOTE**<br>
2667> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#addService](js-apis-bluetooth-ble.md#addservice).
2668
2669**Required permissions**: ohos.permission.USE_BLUETOOTH
2670
2671**System capability**: SystemCapability.Communication.Bluetooth.Core
2672
2673**Parameters**
2674
2675| Name    | Type                         | Mandatory  | Description                      |
2676| ------- | --------------------------- | ---- | ------------------------ |
2677| service | [GattService](#gattservice) | Yes   | Service to add. Settings related to BLE advertising.|
2678
2679**Error codes**
2680
2681For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2682
2683| ID| Error Message|
2684| -------- | ---------------------------- |
2685|2900001 | Service stopped.                         |
2686|2900003 | Bluetooth switch is off.                 |
2687|2900099 | Operation failed.                        |
2688
2689**Example**
2690
2691```js
2692// Create descriptors.
2693let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
2694let arrayBuffer = new ArrayBuffer(8);
2695let descV = new Uint8Array(arrayBuffer);
2696descV[0] = 11;
2697let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2698    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2699    descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
2700descriptors[0] = descriptor;
2701
2702// Create characteristics.
2703let characteristics: Array<bluetoothManager.BLECharacteristic> = [];
2704let arrayBufferC = new ArrayBuffer(8);
2705let cccV = new Uint8Array(arrayBufferC);
2706cccV[0] = 1;
2707let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2708    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
2709let characteristicN: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2710    characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
2711characteristics[0] = characteristic;
2712
2713// Create a gattService instance.
2714let gattService: bluetoothManager.GattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, characteristics:characteristics, includeServices:[]};
2715
2716let gattServer  = bluetoothManager.BLE.createGattServer();
2717try {
2718    gattServer.addService(gattService);
2719} catch (err) {
2720    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2721}
2722```
2723
2724
2725### removeService<sup>(deprecated)</sup>
2726
2727removeService(serviceUuid: string): void
2728
2729Removes a service from this GATT server.
2730
2731> **NOTE**<br>
2732> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#removeService](js-apis-bluetooth-ble.md#removeservice).
2733
2734**Required permissions**: ohos.permission.USE_BLUETOOTH
2735
2736**System capability**: SystemCapability.Communication.Bluetooth.Core
2737
2738**Parameters**
2739
2740| Name        | Type    | Mandatory  | Description                                      |
2741| ----------- | ------ | ---- | ---------------------------------------- |
2742| serviceUuid | string | Yes   | Universally unique identifier (UUID) of the service to remove, for example, **00001810-0000-1000-8000-00805F9B34FB**.|
2743
2744**Error codes**
2745
2746For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2747
2748| ID| Error Message|
2749| -------- | ---------------------------- |
2750|2900001 | Service stopped.                         |
2751|2900003 | Bluetooth switch is off.                 |
2752|2900004 | Profile is not supported.                |
2753|2900099 | Operation failed.                        |
2754
2755**Example**
2756
2757```js
2758let server = bluetoothManager.BLE.createGattServer();
2759try {
2760    server.removeService('00001810-0000-1000-8000-00805F9B34FB');
2761} catch (err) {
2762    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2763}
2764```
2765
2766
2767### close<sup>(deprecated)</sup>
2768
2769close(): void
2770
2771Closes this GATT server to unregister it from the protocol stack. After this method is called, this [GattServer](#gattserver) cannot be used.
2772
2773> **NOTE**<br>
2774> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#close](js-apis-bluetooth-ble.md#close).
2775
2776**Required permissions**: ohos.permission.USE_BLUETOOTH
2777
2778**System capability**: SystemCapability.Communication.Bluetooth.Core
2779
2780**Error codes**
2781
2782For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2783
2784| ID| Error Message|
2785| -------- | ---------------------------- |
2786|2900001 | Service stopped.                         |
2787|2900003 | Bluetooth switch is off.                 |
2788|2900099 | Operation failed.                        |
2789
2790**Example**
2791
2792```js
2793let server = bluetoothManager.BLE.createGattServer();
2794try {
2795    server.close();
2796} catch (err) {
2797    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2798}
2799```
2800
2801
2802### notifyCharacteristicChanged<sup>(deprecated)</sup>
2803
2804notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): void
2805
2806Notifies the connected client device when a characteristic value changes.
2807
2808> **NOTE**<br>
2809> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#notifyCharacteristicChanged](js-apis-bluetooth-ble.md#notifycharacteristicchanged).
2810
2811**Required permissions**: ohos.permission.USE_BLUETOOTH
2812
2813**System capability**: SystemCapability.Communication.Bluetooth.Core
2814
2815**Parameters**
2816
2817| Name                 | Type                                      | Mandatory  | Description                                     |
2818| -------------------- | ---------------------------------------- | ---- | --------------------------------------- |
2819| deviceId             | string                                   | Yes   | Address of the client that receives notifications, for example, XX:XX:XX:XX:XX:XX.|
2820| notifyCharacteristic | [NotifyCharacteristic](#notifycharacteristic) | Yes   | New characteristic value.                              |
2821
2822**Error codes**
2823
2824For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2825
2826| ID| Error Message|
2827| -------- | ---------------------------- |
2828|2900001 | Service stopped.                         |
2829|2900003 | Bluetooth switch is off.                 |
2830|2900099 | Operation failed.                        |
2831
2832**Example**
2833
2834```js
2835// Create descriptors.
2836let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
2837let arrayBuffer = new ArrayBuffer(8);
2838let descV = new Uint8Array(arrayBuffer);
2839descV[0] = 11;
2840let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2841    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2842    descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
2843descriptors[0] = descriptor;
2844let arrayBufferC = new ArrayBuffer(8);
2845let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2846  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
2847let notifyCharacteristic: bluetoothManager.NotifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2848  characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false};
2849let server = bluetoothManager.BLE.createGattServer();
2850try {
2851    server.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacteristic);
2852} catch (err) {
2853    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2854}
2855```
2856
2857
2858### sendResponse<sup>(deprecated)</sup>
2859
2860sendResponse(serverResponse: ServerResponse): void
2861
2862Sends a response to a read or write request from the GATT client.
2863
2864> **NOTE**<br>
2865> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#sendResponse](js-apis-bluetooth-ble.md#sendresponse).
2866
2867**Required permissions**: ohos.permission.USE_BLUETOOTH
2868
2869**System capability**: SystemCapability.Communication.Bluetooth.Core
2870
2871**Parameters**
2872
2873| Name           | Type                               | Mandatory  | Description             |
2874| -------------- | --------------------------------- | ---- | --------------- |
2875| serverResponse | [ServerResponse](#serverresponse) | Yes   | Response returned by the GATT server.|
2876
2877**Error codes**
2878
2879For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
2880
2881| ID| Error Message|
2882| -------- | ---------------------------- |
2883|2900001 | Service stopped.                         |
2884|2900003 | Bluetooth switch is off.                 |
2885|2900099 | Operation failed.                        |
2886
2887**Example**
2888
2889```js
2890/* send response */
2891let arrayBufferCCC = new ArrayBuffer(8);
2892let cccValue = new Uint8Array(arrayBufferCCC);
2893cccValue[0] = 1123;
2894let serverResponse: bluetoothManager.ServerResponse = {
2895    deviceId: 'XX:XX:XX:XX:XX:XX',
2896    transId: 0,
2897    status: 0,
2898    offset: 0,
2899    value: arrayBufferCCC,
2900};
2901
2902let gattServer = bluetoothManager.BLE.createGattServer();
2903try {
2904    gattServer.sendResponse(serverResponse);
2905} catch (err) {
2906    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2907}
2908```
2909
2910
2911### on('characteristicRead')<sup>(deprecated)</sup>
2912
2913on(type: "characteristicRead", callback: Callback&lt;CharacteristicReadRequest&gt;): void
2914
2915Subscribes to the characteristic read request events.
2916
2917> **NOTE**<br>
2918> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('characteristicRead')](js-apis-bluetooth-ble.md#oncharacteristicread).
2919
2920**Required permissions**: ohos.permission.USE_BLUETOOTH
2921
2922**System capability**: SystemCapability.Communication.Bluetooth.Core
2923
2924**Parameters**
2925
2926| Name     | Type                                      | Mandatory  | Description                                   |
2927| -------- | ---------------------------------------- | ---- | ------------------------------------- |
2928| type     | string                                   | Yes   | Event type. The value **characteristicRead** indicates a characteristic read request event.|
2929| callback | Callback&lt;[CharacteristicReadRequest](#characteristicreadrequest)&gt; | Yes   | Callback invoked to return a characteristic read request event from the GATT client.           |
2930
2931**Example**
2932
2933```js
2934let arrayBufferCCC = new ArrayBuffer(8);
2935let cccValue = new Uint8Array(arrayBufferCCC);
2936cccValue[0] = 1123;
2937function ReadCharacteristicReq(characteristicReadRequest: bluetoothManager.CharacteristicReadRequest) {
2938    let deviceId: string = characteristicReadRequest.deviceId;
2939    let transId: number = characteristicReadRequest.transId;
2940    let offset: number = characteristicReadRequest.offset;
2941    let characteristicUuid: string = characteristicReadRequest.characteristicUuid;
2942
2943    let serverResponse: bluetoothManager.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
2944
2945    try {
2946        gattServer.sendResponse(serverResponse);
2947    } catch (err) {
2948        console.error('errCode: ' + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2949    }
2950}
2951
2952let gattServer = bluetoothManager.BLE.createGattServer();
2953gattServer.on("characteristicRead", ReadCharacteristicReq);
2954```
2955
2956
2957### off('characteristicRead')<sup>(deprecated)</sup>
2958
2959off(type: "characteristicRead", callback?: Callback&lt;CharacteristicReadRequest&gt;): void
2960
2961Unsubscribes from the characteristic read request events.
2962
2963> **NOTE**<br>
2964> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('characteristicRead')](js-apis-bluetooth-ble.md#offcharacteristicread).
2965
2966**Required permissions**: ohos.permission.USE_BLUETOOTH
2967
2968**System capability**: SystemCapability.Communication.Bluetooth.Core
2969
2970**Parameters**
2971
2972| Name     | Type                                      | Mandatory  | Description                                      |
2973| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2974| type     | string                                   | Yes   | Event type. The value **characteristicRead** indicates a characteristic read request event.   |
2975| callback | Callback&lt;[CharacteristicReadRequest](#characteristicreadrequest)&gt; | No   | Callback for the characteristic read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
2976
2977**Example**
2978
2979```js
2980let gattServer = bluetoothManager.BLE.createGattServer();
2981gattServer.off("characteristicRead");
2982```
2983
2984
2985### on('characteristicWrite')<sup>(deprecated)</sup>
2986
2987on(type: "characteristicWrite", callback: Callback&lt;CharacteristicWriteRequest&gt;): void
2988
2989Subscribes to the characteristic write request events.
2990
2991> **NOTE**<br>
2992> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('characteristicWrite')](js-apis-bluetooth-ble.md#oncharacteristicwrite).
2993
2994**Required permissions**: ohos.permission.USE_BLUETOOTH
2995
2996**System capability**: SystemCapability.Communication.Bluetooth.Core
2997
2998**Parameters**
2999
3000| Name     | Type                                      | Mandatory  | Description                                    |
3001| -------- | ---------------------------------------- | ---- | -------------------------------------- |
3002| type     | string                                   | Yes   | Event type. The value **characteristicWrite** indicates a characteristic write request event.|
3003| callback | Callback&lt;[CharacteristicWriteRequest](#characteristicwriterequest)&gt; | Yes   | Callback invoked to return a characteristic write request from the GATT client.            |
3004
3005**Example**
3006
3007```js
3008let arrayBufferCCC = new ArrayBuffer(8);
3009let cccValue = new Uint8Array(arrayBufferCCC);
3010function WriteCharacteristicReq(characteristicWriteRequest: bluetoothManager.CharacteristicWriteRequest) {
3011    let deviceId: string = characteristicWriteRequest.deviceId;
3012    let transId: number = characteristicWriteRequest.transId;
3013    let offset: number = characteristicWriteRequest.offset;
3014    let isPrep: boolean = characteristicWriteRequest.isPrep;
3015    let needRsp: boolean = characteristicWriteRequest.needRsp;
3016    let value: Uint8Array =  new Uint8Array(characteristicWriteRequest.value);
3017    let characteristicUuid: string = characteristicWriteRequest.characteristicUuid;
3018
3019    cccValue[0] = value[0];
3020    let serverResponse: bluetoothManager.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
3021
3022    try {
3023        gattServer.sendResponse(serverResponse);
3024    } catch (err) {
3025        console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
3026    }
3027}
3028
3029let gattServer = bluetoothManager.BLE.createGattServer();
3030gattServer.on("characteristicWrite", WriteCharacteristicReq);
3031```
3032
3033
3034### off('characteristicWrite')<sup>(deprecated)</sup>
3035
3036off(type: "characteristicWrite", callback?: Callback&lt;CharacteristicWriteRequest&gt;): void
3037
3038Unsubscribes from the characteristic write request events.
3039
3040> **NOTE**<br>
3041> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('characteristicWrite')](js-apis-bluetooth-ble.md#offcharacteristicwrite).
3042
3043**Required permissions**: ohos.permission.USE_BLUETOOTH
3044
3045**System capability**: SystemCapability.Communication.Bluetooth.Core
3046
3047**Parameters**
3048
3049| Name     | Type                                      | Mandatory  | Description                                      |
3050| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3051| type     | string                                   | Yes   | Event type. The value **characteristicWrite** indicates a characteristic write request event.  |
3052| callback | Callback&lt;[CharacteristicWriteRequest](#characteristicwriterequest)&gt; | No   | Callback for the characteristic write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
3053
3054**Example**
3055
3056```js
3057let gattServer = bluetoothManager.BLE.createGattServer();
3058gattServer.off("characteristicWrite");
3059```
3060
3061
3062### on('descriptorRead')<sup>(deprecated)</sup>
3063
3064on(type: "descriptorRead", callback: Callback&lt;DescriptorReadRequest&gt;): void
3065
3066Subscribes to the descriptor read request events.
3067
3068> **NOTE**<br>
3069> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('descriptorRead')](js-apis-bluetooth-ble.md#ondescriptorread).
3070
3071**Required permissions**: ohos.permission.USE_BLUETOOTH
3072
3073**System capability**: SystemCapability.Communication.Bluetooth.Core
3074
3075**Parameters**
3076
3077| Name     | Type                                      | Mandatory  | Description                               |
3078| -------- | ---------------------------------------- | ---- | --------------------------------- |
3079| type     | string                                   | Yes   | Event type. The value **descriptorRead** indicates a descriptor read request event.|
3080| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequest)&gt; | Yes   | Callback invoked to return a descriptor read request event from the GATT client.       |
3081
3082**Example**
3083
3084```js
3085let arrayBufferDesc = new ArrayBuffer(8);
3086let descValue = new Uint8Array(arrayBufferDesc);
3087descValue[0] = 1101;
3088function ReadDescriptorReq(descriptorReadRequest: bluetoothManager.DescriptorReadRequest) {
3089    let deviceId: string = descriptorReadRequest.deviceId;
3090    let transId: number = descriptorReadRequest.transId;
3091    let offset: number = descriptorReadRequest.offset;
3092    let descriptorUuid: string = descriptorReadRequest.descriptorUuid;
3093
3094    let serverResponse: bluetoothManager.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
3095
3096    try {
3097        gattServer.sendResponse(serverResponse);
3098    } catch (err) {
3099        console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
3100    }
3101}
3102
3103let gattServer = bluetoothManager.BLE.createGattServer();
3104gattServer.on("descriptorRead", ReadDescriptorReq);
3105```
3106
3107
3108### off('descriptorRead')<sup>(deprecated)</sup>
3109
3110off(type: "descriptorRead", callback?: Callback&lt;DescriptorReadRequest&gt;): void
3111
3112Unsubscribes from the descriptor read request events.
3113
3114> **NOTE**<br>
3115> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('descriptorRead')](js-apis-bluetooth-ble.md#offdescriptorread).
3116
3117**Required permissions**: ohos.permission.USE_BLUETOOTH
3118
3119**System capability**: SystemCapability.Communication.Bluetooth.Core
3120
3121**Parameters**
3122
3123| Name     | Type                                      | Mandatory  | Description                                      |
3124| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3125| type     | string                                   | Yes   | Event type. The value **descriptorRead** indicates a descriptor read request event.       |
3126| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequest)&gt; | No   | Callback for the descriptor read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
3127
3128**Example**
3129
3130```js
3131let gattServer = bluetoothManager.BLE.createGattServer();
3132gattServer.off("descriptorRead");
3133```
3134
3135
3136### on('descriptorWrite')<sup>(deprecated)</sup>
3137
3138on(type: "descriptorWrite", callback: Callback&lt;DescriptorWriteRequest&gt;): void
3139
3140Subscribes to the descriptor write request events.
3141
3142> **NOTE**<br>
3143> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('descriptorWrite')](js-apis-bluetooth-ble.md#ondescriptorwrite).
3144
3145**Required permissions**: ohos.permission.USE_BLUETOOTH
3146
3147**System capability**: SystemCapability.Communication.Bluetooth.Core
3148
3149**Parameters**
3150
3151| Name     | Type                                      | Mandatory  | Description                                |
3152| -------- | ---------------------------------------- | ---- | ---------------------------------- |
3153| type     | string                                   | Yes   | Event type. The value **descriptorWrite** indicates a descriptor write request event.|
3154| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequest)&gt; | Yes   | Callback invoked to return a descriptor write request from the GATT client.        |
3155
3156**Example**
3157
3158```js
3159let arrayBufferDesc = new ArrayBuffer(8);
3160let descValue = new Uint8Array(arrayBufferDesc);
3161function WriteDescriptorReq(descriptorWriteRequest: bluetoothManager.DescriptorWriteRequest) {
3162    let deviceId: string = descriptorWriteRequest.deviceId;
3163    let transId: number = descriptorWriteRequest.transId;
3164    let offset: number = descriptorWriteRequest.offset;
3165    let isPrep: boolean = descriptorWriteRequest.isPrep;
3166    let needRsp: boolean = descriptorWriteRequest.needRsp;
3167    let value: Uint8Array = new Uint8Array(descriptorWriteRequest.value);
3168    let descriptorUuid: string = descriptorWriteRequest.descriptorUuid;
3169
3170    descValue[0] = value[0];
3171    let serverResponse: bluetoothManager.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
3172
3173    try {
3174        gattServer.sendResponse(serverResponse);
3175    } catch (err) {
3176        console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
3177    }
3178}
3179
3180let gattServer = bluetoothManager.BLE.createGattServer();
3181gattServer.on("descriptorWrite", WriteDescriptorReq);
3182```
3183
3184
3185### off('descriptorWrite')<sup>(deprecated)</sup>
3186
3187off(type: "descriptorWrite", callback?: Callback&lt;DescriptorWriteRequest&gt;): void
3188
3189Unsubscribes from the descriptor write request events.
3190
3191> **NOTE**<br>
3192> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('descriptorWrite')](js-apis-bluetooth-ble.md#offdescriptorwrite).
3193
3194**Required permissions**: ohos.permission.USE_BLUETOOTH
3195
3196**System capability**: SystemCapability.Communication.Bluetooth.Core
3197
3198**Parameters**
3199
3200| Name     | Type                                      | Mandatory  | Description                                      |
3201| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3202| type     | string                                   | Yes   | Event type. The value **descriptorWrite** indicates a descriptor write request event.      |
3203| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequest)&gt; | No   | Callback for the descriptor write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
3204
3205**Example**
3206
3207```js
3208let gattServer = bluetoothManager.BLE.createGattServer();
3209gattServer.off("descriptorWrite");
3210```
3211
3212
3213### on('connectStateChange')<sup>(deprecated)</sup>
3214
3215on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
3216
3217Subscribes to the BLE connection state changes.
3218
3219> **NOTE**<br>
3220> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#on('connectionStateChange')](js-apis-bluetooth-ble.md#onconnectionstatechange).
3221
3222**Required permissions**: ohos.permission.USE_BLUETOOTH
3223
3224**System capability**: SystemCapability.Communication.Bluetooth.Core
3225
3226**Parameters**
3227
3228| Name     | Type                                      | Mandatory  | Description                                      |
3229| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3230| type     | string                                   | Yes   | Event type. The value **connectStateChange** indicates a BLE connection state change event.|
3231| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | Yes   | Callback invoked to return the BLE connection state.                         |
3232
3233**Example**
3234
3235```js
3236function Connected(BLEConnectChangedState: bluetoothManager.BLEConnectChangedState) {
3237  let deviceId: string = BLEConnectChangedState.deviceId;
3238  let status: bluetoothManager.ProfileConnectionState  = BLEConnectChangedState.state;
3239}
3240
3241let gattServer = bluetoothManager.BLE.createGattServer();
3242gattServer.on("connectStateChange", Connected);
3243```
3244
3245
3246### off('connectStateChange')<sup>(deprecated)</sup>
3247
3248off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
3249
3250Unsubscribes from the BLE connection state changes.
3251
3252> **NOTE**<br>
3253> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattServer#off('connectionStateChange')](js-apis-bluetooth-ble.md#offconnectionstatechange).
3254
3255**Required permissions**: ohos.permission.USE_BLUETOOTH
3256
3257**System capability**: SystemCapability.Communication.Bluetooth.Core
3258
3259**Parameters**
3260
3261| Name     | Type                                      | Mandatory  | Description                                      |
3262| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3263| type     | string                                   | Yes   | Event type. The value **connectStateChange** indicates a BLE connection state change event.|
3264| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | No   | Callback for the BLE connection state change event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
3265
3266**Example**
3267
3268```js
3269let gattServer = bluetoothManager.BLE.createGattServer();
3270gattServer.off("connectStateChange");
3271```
3272
3273
3274## GattClientDevice
3275
3276Implements the GATT client. Before using an API of this class, you must create a **GattClientDevice** instance using **createGattClientDevice(deviceId: string)**.
3277
3278> **NOTE**<br>
3279> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice](js-apis-bluetooth-ble.md#gattclientdevice).
3280
3281
3282### connect<sup>(deprecated)</sup>
3283
3284connect(): void
3285
3286Initiates a connection to the remote BLE device.
3287
3288> **NOTE**<br>
3289> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#connect](js-apis-bluetooth-ble.md#connect).
3290
3291**Required permissions**: ohos.permission.USE_BLUETOOTH
3292
3293**System capability**: SystemCapability.Communication.Bluetooth.Core
3294
3295**Error codes**
3296
3297For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3298
3299| ID| Error Message|
3300| -------- | ---------------------------- |
3301|2900001 | Service stopped.                         |
3302|2900003 | Bluetooth switch is off.                 |
3303|2900099 | Operation failed.                        |
3304
3305**Example**
3306
3307```js
3308try {
3309    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3310    device.connect();
3311} catch (err) {
3312    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3313}
3314```
3315
3316
3317### disconnect<sup>(deprecated)</sup>
3318
3319disconnect(): void
3320
3321Disconnects from the remote BLE device.
3322
3323> **NOTE**<br>
3324> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#disconnect](js-apis-bluetooth-ble.md#disconnect).
3325
3326**Required permissions**: ohos.permission.USE_BLUETOOTH
3327
3328**System capability**: SystemCapability.Communication.Bluetooth.Core
3329
3330**Error codes**
3331
3332For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3333
3334| ID| Error Message|
3335| -------- | ---------------------------- |
3336|2900001 | Service stopped.                         |
3337|2900003 | Bluetooth switch is off.                 |
3338|2900099 | Operation failed.                        |
3339
3340**Example**
3341
3342```js
3343try {
3344    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3345    device.disconnect();
3346} catch (err) {
3347    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3348}
3349```
3350
3351
3352### close<sup>(deprecated)</sup>
3353
3354close(): void
3355
3356Closes this GATT client to unregister it from the protocol stack. After this method is called, this [GattClientDevice](#gattclientdevice) instance cannot be used.
3357
3358> **NOTE**<br>
3359> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#close](js-apis-bluetooth-ble.md#close).
3360
3361**Required permissions**: ohos.permission.USE_BLUETOOTH
3362
3363**System capability**: SystemCapability.Communication.Bluetooth.Core
3364
3365**Error codes**
3366
3367For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3368
3369| ID| Error Message|
3370| -------- | ---------------------------- |
3371|2900001 | Service stopped.                         |
3372|2900003 | Bluetooth switch is off.                 |
3373|2900099 | Operation failed.                        |
3374
3375**Example**
3376
3377```js
3378try {
3379    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3380    device.close();
3381} catch (err) {
3382    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3383}
3384```
3385
3386
3387
3388
3389### getServices<sup>(deprecated)</sup>
3390
3391getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void
3392
3393Obtains all services of the remote BLE device. This API uses an asynchronous callback to return the result.
3394
3395> **NOTE**<br>
3396> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getServices](js-apis-bluetooth-ble.md#getservices).
3397
3398**Required permissions**: ohos.permission.USE_BLUETOOTH
3399
3400**System capability**: SystemCapability.Communication.Bluetooth.Core
3401
3402**Parameters**
3403
3404| Name     | Type                                      | Mandatory  | Description                      |
3405| -------- | ---------------------------------------- | ---- | ------------------------ |
3406| callback | AsyncCallback&lt;Array&lt;[GattService](#gattservice)&gt;&gt; | Yes   | Callback invoked to return the services obtained.|
3407
3408**Error codes**
3409
3410For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3411
3412| ID| Error Message|
3413| -------- | ---------------------------- |
3414|2900001 | Service stopped.                         |
3415|2900099 | Operation failed.                        |
3416
3417**Example**
3418
3419```js
3420// Callback
3421function getServices(code: BusinessError, gattServices: Array<bluetoothManager.GattService>) {
3422  if (code.code == 0) {
3423      let services: Array<bluetoothManager.GattService> = gattServices;
3424      console.log('bluetooth code is ' + code.code);
3425      console.log("bluetooth services size is ", services.length);
3426
3427      for (let i = 0; i < services.length; i++) {
3428        console.log('bluetooth serviceUuid is ' + services[i].serviceUuid);
3429      }
3430  }
3431}
3432
3433try {
3434    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3435    device.connect();
3436    device.getServices(getServices);
3437} catch (err) {
3438    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3439}
3440```
3441
3442
3443### getServices<sup>(deprecated)</sup>
3444
3445getServices(): Promise&lt;Array&lt;GattService&gt;&gt;
3446
3447Obtains all services of the remote BLE device. This API uses a promise to return the result.
3448
3449> **NOTE**<br>
3450> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getServices](js-apis-bluetooth-ble.md#getservices-1).
3451
3452**Required permissions**: ohos.permission.USE_BLUETOOTH
3453
3454**System capability**: SystemCapability.Communication.Bluetooth.Core
3455
3456**Return value**
3457
3458| Type                                      | Description                         |
3459| ---------------------------------------- | --------------------------- |
3460| Promise&lt;Array&lt;[GattService](#gattservice)&gt;&gt; | Promise used to return the services obtained.|
3461
3462**Error codes**
3463
3464For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3465
3466| ID| Error Message|
3467| -------- | ---------------------------- |
3468|2900001 | Service stopped.                         |
3469|2900099 | Operation failed.                        |
3470
3471**Example**
3472
3473```js
3474// Promise
3475try {
3476    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3477    device.connect();
3478    device.getServices().then(result => {
3479        console.info("getServices successfully:" + JSON.stringify(result));
3480    });
3481} catch (err) {
3482    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3483}
3484```
3485
3486
3487### readCharacteristicValue<sup>(deprecated)</sup>
3488
3489readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void
3490
3491Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
3492
3493> **NOTE**<br>
3494> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#readCharacteristicValue](js-apis-bluetooth-ble.md#readcharacteristicvalue).
3495
3496**Required permissions**: ohos.permission.USE_BLUETOOTH
3497
3498**System capability**: SystemCapability.Communication.Bluetooth.Core
3499
3500**Parameters**
3501
3502| Name           | Type                                      | Mandatory  | Description                     |
3503| -------------- | ---------------------------------------- | ---- | ----------------------- |
3504| characteristic | [BLECharacteristic](#blecharacteristic)  | Yes   | Characteristic value to read.               |
3505| callback       | AsyncCallback&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes   | Callback invoked to return the characteristic value read.|
3506
3507**Error codes**
3508
3509For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3510
3511| ID| Error Message|
3512| -------- | ---------------------------- |
3513|2900001 | Service stopped.                         |
3514|2901000 | Read forbidden.                         |
3515|2900099 | Operation failed.                        |
3516
3517**Example**
3518
3519```js
3520function readCcc(code: BusinessError, BLECharacteristic: bluetoothManager.BLECharacteristic) {
3521    if (code.code != 0) {
3522        return;
3523    }
3524    console.log('bluetooth characteristic uuid: ' + BLECharacteristic.characteristicUuid);
3525    let value = new Uint8Array(BLECharacteristic.characteristicValue);
3526    console.log('bluetooth characteristic value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
3527}
3528
3529let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
3530let bufferDesc = new ArrayBuffer(8);
3531let descV = new Uint8Array(bufferDesc);
3532descV[0] = 11;
3533let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3534    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3535    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
3536descriptors[0] = descriptor;
3537
3538let bufferCCC = new ArrayBuffer(8);
3539let cccV = new Uint8Array(bufferCCC);
3540cccV[0] = 1;
3541let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3542    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3543    characteristicValue: bufferCCC, descriptors:descriptors};
3544
3545try {
3546    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3547    device.readCharacteristicValue(characteristic, readCcc);
3548} catch (err) {
3549    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3550}
3551```
3552
3553
3554### readCharacteristicValue<sup>(deprecated)</sup>
3555
3556readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt;
3557
3558Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
3559
3560> **NOTE**<br>
3561> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#readCharacteristicValue](js-apis-bluetooth-ble.md#readcharacteristicvalue-1).
3562
3563**Required permissions**: ohos.permission.USE_BLUETOOTH
3564
3565**System capability**: SystemCapability.Communication.Bluetooth.Core
3566
3567**Parameters**
3568
3569| Name           | Type                                     | Mandatory  | Description      |
3570| -------------- | --------------------------------------- | ---- | -------- |
3571| characteristic | [BLECharacteristic](#blecharacteristic) | Yes   | Characteristic value to read.|
3572
3573**Return value**
3574
3575| Type                                      | Description                        |
3576| ---------------------------------------- | -------------------------- |
3577| Promise&lt;[BLECharacteristic](#blecharacteristic)&gt; | Promise used to return the characteristic value read.|
3578
3579**Error codes**
3580
3581For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3582
3583| ID| Error Message|
3584| -------- | ---------------------------- |
3585|2900001 | Service stopped.                         |
3586|2901000 | Read forbidden.                         |
3587|2900099 | Operation failed.                        |
3588
3589**Example**
3590
3591```js
3592let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
3593let bufferDesc = new ArrayBuffer(8);
3594let descV = new Uint8Array(bufferDesc);
3595descV[0] = 11;
3596let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3597    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3598    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
3599descriptors[0] = descriptor;
3600
3601let bufferCCC = new ArrayBuffer(8);
3602let cccV = new Uint8Array(bufferCCC);
3603cccV[0] = 1;
3604let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3605    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3606    characteristicValue: bufferCCC, descriptors:descriptors};
3607
3608try {
3609    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3610    device.readCharacteristicValue(characteristic);
3611} catch (err) {
3612    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3613}
3614```
3615
3616
3617### readDescriptorValue<sup>(deprecated)</sup>
3618
3619readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void
3620
3621Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
3622
3623> **NOTE**<br>
3624> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#readDescriptorValue](js-apis-bluetooth-ble.md#readdescriptorvalue).
3625
3626**Required permissions**: ohos.permission.USE_BLUETOOTH
3627
3628**System capability**: SystemCapability.Communication.Bluetooth.Core
3629
3630**Parameters**
3631
3632| Name       | Type                                      | Mandatory  | Description                     |
3633| ---------- | ---------------------------------------- | ---- | ----------------------- |
3634| descriptor | [BLEDescriptor](#bledescriptor)          | Yes   | Descriptor to read.               |
3635| callback   | AsyncCallback&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes   | Callback invoked to return the descriptor read.|
3636
3637**Error codes**
3638
3639For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3640
3641| ID| Error Message|
3642| -------- | ---------------------------- |
3643|2900001 | Service stopped.                         |
3644|2901000 | Read forbidden.                         |
3645|2900099 | Operation failed.                        |
3646
3647**Example**
3648
3649```js
3650function readDesc(code: BusinessError, BLEDescriptor: bluetoothManager.BLEDescriptor) {
3651    if (code.code != 0) {
3652        return;
3653    }
3654    console.log('bluetooth descriptor uuid: ' + BLEDescriptor.descriptorUuid);
3655    let value = new Uint8Array(BLEDescriptor.descriptorValue);
3656    console.log('bluetooth descriptor value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
3657}
3658
3659let bufferDesc = new ArrayBuffer(8);
3660let descV = new Uint8Array(bufferDesc);
3661descV[0] = 11;
3662let descriptor: bluetoothManager.BLEDescriptor = {
3663    serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3664    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3665    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
3666    descriptorValue: bufferDesc
3667};
3668try {
3669    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3670    device.readDescriptorValue(descriptor, readDesc);
3671} catch (err) {
3672    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3673}
3674```
3675
3676
3677### readDescriptorValue<sup>(deprecated)</sup>
3678
3679readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt;
3680
3681Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
3682
3683> **NOTE**<br>
3684> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#readDescriptorValue](js-apis-bluetooth-ble.md#readdescriptorvalue-1).
3685
3686**Required permissions**: ohos.permission.USE_BLUETOOTH
3687
3688**System capability**: SystemCapability.Communication.Bluetooth.Core
3689
3690**Parameters**
3691
3692| Name       | Type                             | Mandatory  | Description      |
3693| ---------- | ------------------------------- | ---- | -------- |
3694| descriptor | [BLEDescriptor](#bledescriptor) | Yes   | Descriptor to read.|
3695
3696**Return value**
3697
3698| Type                                      | Description                        |
3699| ---------------------------------------- | -------------------------- |
3700| Promise&lt;[BLEDescriptor](#bledescriptor)&gt; | Promise used to return the descriptor read.|
3701
3702**Error codes**
3703
3704For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3705
3706| ID| Error Message|
3707| -------- | ---------------------------- |
3708|2900001 | Service stopped.                         |
3709|2901000 | Read forbidden.                         |
3710|2900099 | Operation failed.                        |
3711
3712**Example**
3713
3714```js
3715let bufferDesc = new ArrayBuffer(8);
3716let descV = new Uint8Array(bufferDesc);
3717descV[0] = 11;
3718let descriptor: bluetoothManager.BLEDescriptor = {
3719    serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3720    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3721    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
3722    descriptorValue: bufferDesc
3723};
3724try {
3725    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3726    device.readDescriptorValue(descriptor);
3727} catch (err) {
3728    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3729}
3730```
3731
3732
3733### writeCharacteristicValue<sup>(deprecated)</sup>
3734
3735writeCharacteristicValue(characteristic: BLECharacteristic): void
3736
3737Writes a characteristic value to the remote BLE device.
3738
3739> **NOTE**<br>
3740> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#writeCharacteristicValue](js-apis-bluetooth-ble.md#writecharacteristicvalue).
3741
3742**Required permissions**: ohos.permission.USE_BLUETOOTH
3743
3744**System capability**: SystemCapability.Communication.Bluetooth.Core
3745
3746**Parameters**
3747
3748| Name           | Type                                     | Mandatory  | Description                 |
3749| -------------- | --------------------------------------- | ---- | ------------------- |
3750| characteristic | [BLECharacteristic](#blecharacteristic) | Yes   | Binary value and other parameters of the BLE device characteristic.|
3751
3752**Error codes**
3753
3754For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3755
3756| ID| Error Message|
3757| -------- | ---------------------------- |
3758|2900001 | Service stopped.                         |
3759|2901001 | Write forbidden.                        |
3760|2900099 | Operation failed.                        |
3761
3762**Example**
3763
3764```js
3765let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
3766let bufferDesc = new ArrayBuffer(8);
3767let descV = new Uint8Array(bufferDesc);
3768descV[0] = 11;
3769let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3770    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3771    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
3772descriptors[0] = descriptor;
3773
3774let bufferCCC = new ArrayBuffer(8);
3775let cccV = new Uint8Array(bufferCCC);
3776cccV[0] = 1;
3777let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3778    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3779    characteristicValue: bufferCCC, descriptors:descriptors};
3780try {
3781    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3782    device.writeCharacteristicValue(characteristic);
3783} catch (err) {
3784    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3785}
3786```
3787
3788
3789### writeDescriptorValue<sup>(deprecated)</sup>
3790
3791writeDescriptorValue(descriptor: BLEDescriptor): void
3792
3793Writes binary data to the specific descriptor of the remote BLE device.
3794
3795> **NOTE**<br>
3796> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#writeCharacteristicValue](js-apis-bluetooth-ble.md#writecharacteristicvalue-1).
3797
3798**Required permissions**: ohos.permission.USE_BLUETOOTH
3799
3800**System capability**: SystemCapability.Communication.Bluetooth.Core
3801
3802**Parameters**
3803
3804| Name       | Type                             | Mandatory  | Description                |
3805| ---------- | ------------------------------- | ---- | ------------------ |
3806| descriptor | [BLEDescriptor](#bledescriptor) | Yes   | Binary value and other parameters of the BLE device descriptor.|
3807| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3808
3809**Error codes**
3810
3811For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3812
3813| ID| Error Message|
3814| -------- | ---------------------------- |
3815|2900001 | Service stopped.                         |
3816|2901001 | Write forbidden.                        |
3817|2900099 | Operation failed.                        |
3818
3819**Example**
3820
3821```js
3822let bufferDesc = new ArrayBuffer(8);
3823let descV = new Uint8Array(bufferDesc);
3824descV[0] = 22;
3825let descriptor: bluetoothManager.BLEDescriptor = {
3826    serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3827    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3828    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
3829    descriptorValue: bufferDesc
3830};
3831try {
3832    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3833    device.writeDescriptorValue(descriptor);
3834} catch (err) {
3835    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3836}
3837```
3838
3839
3840### setBLEMtuSize<sup>(deprecated)</sup>
3841
3842setBLEMtuSize(mtu: number): void
3843
3844Sets the maximum transmission unit (MTU) that can be transmitted between the GATT client and its remote BLE device. This API can be used only after a connection is set up by calling [connect](#connect).
3845
3846> **NOTE**<br>
3847> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#setBLEMtuSize](js-apis-bluetooth-ble.md#setBLEMtuSize).
3848
3849**Required permissions**: ohos.permission.USE_BLUETOOTH
3850
3851**System capability**: SystemCapability.Communication.Bluetooth.Core
3852
3853**Parameters**
3854
3855| Name | Type    | Mandatory  | Description            |
3856| ---- | ------ | ---- | -------------- |
3857| mtu  | number | Yes   | MTU to set, which ranges from 22 to 512 bytes.|
3858
3859**Error codes**
3860
3861For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3862
3863| ID| Error Message|
3864| -------- | ---------------------------- |
3865|2900001 | Service stopped.                         |
3866|2900099 | Operation failed.                        |
3867
3868**Example**
3869
3870```js
3871try {
3872    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3873    device.setBLEMtuSize(128);
3874} catch (err) {
3875    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3876}
3877```
3878
3879
3880### setNotifyCharacteristicChanged<sup>(deprecated)</sup>
3881
3882setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): void
3883
3884Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
3885
3886> **NOTE**<br>
3887> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#setCharacteristicChangeNotification](js-apis-bluetooth-ble.md#setcharacteristicchangenotification).
3888
3889**Required permissions**: ohos.permission.USE_BLUETOOTH
3890
3891**System capability**: SystemCapability.Communication.Bluetooth.Core
3892
3893**Parameters**
3894
3895| Name           | Type                                     | Mandatory  | Description                           |
3896| -------------- | --------------------------------------- | ---- | ----------------------------- |
3897| characteristic | [BLECharacteristic](#blecharacteristic) | Yes   | BLE characteristic to listen for.                     |
3898| enable         | boolean                                 | Yes   | Whether to enable the notify function. The value **true** means to enable the notify function, and the value **false** means the opposite.|
3899
3900**Error codes**
3901
3902For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
3903
3904| ID| Error Message|
3905| -------- | ---------------------------- |
3906|2900001 | Service stopped.                         |
3907|2900099 | Operation failed.                        |
3908
3909**Example**
3910
3911```js
3912// Create descriptors.
3913let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
3914let bufferDesc = new ArrayBuffer(8);
3915let descV = new Uint8Array(bufferDesc);
3916descV[0] = 11;
3917let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3918    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3919    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
3920descriptors[0] = descriptor;
3921
3922let bufferCCC = new ArrayBuffer(8);
3923let cccV = new Uint8Array(bufferCCC);
3924cccV[0] = 1;
3925let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3926    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3927    characteristicValue: bufferCCC, descriptors:descriptors};
3928try {
3929    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3930    device.setNotifyCharacteristicChanged(characteristic, false);
3931} catch (err) {
3932    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3933}
3934
3935```
3936
3937
3938### on('BLECharacteristicChange')<sup>(deprecated)</sup>
3939
3940on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void
3941
3942Subscribes to the BLE characteristic changes. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called.
3943
3944> **NOTE**<br>
3945> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#on('BLECharacteristicChange')](js-apis-bluetooth-ble.md#onblecharacteristicchange).
3946
3947**Required permissions**: ohos.permission.USE_BLUETOOTH
3948
3949**System capability**: SystemCapability.Communication.Bluetooth.Core
3950
3951**Parameters**
3952
3953| Name     | Type                                      | Mandatory  | Description                                      |
3954| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3955| type     | string                                   | Yes   | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
3956| callback | Callback&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes   | Callback invoked to return the characteristic value changes.                 |
3957
3958**Example**
3959
3960```js
3961function CharacteristicChange(characteristicChangeReq: ble.BLECharacteristic) {
3962    let serviceUuid: string = characteristicChangeReq.serviceUuid;
3963    let characteristicUuid: string = characteristicChangeReq.characteristicUuid;
3964    let value: Uint8Array = new Uint8Array(characteristicChangeReq.characteristicValue);
3965}
3966try {
3967    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3968    device.on('BLECharacteristicChange', CharacteristicChange);
3969} catch (err) {
3970    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3971}
3972```
3973
3974
3975### off('BLECharacteristicChange')<sup>(deprecated)</sup>
3976
3977off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void
3978
3979Unsubscribes from the BLE characteristic changes.
3980
3981> **NOTE**<br>
3982> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#off('BLECharacteristicChange')](js-apis-bluetooth-ble.md#offblecharacteristicchange).
3983
3984**Required permissions**: ohos.permission.USE_BLUETOOTH
3985
3986**System capability**: SystemCapability.Communication.Bluetooth.Core
3987
3988**Parameters**
3989
3990| Name     | Type                                      | Mandatory  | Description                                      |
3991| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3992| type     | string                                   | Yes   | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
3993| callback | Callback&lt;[BLECharacteristic](#blecharacteristic)&gt; | No   | Callback for the characteristic value change event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
3994
3995**Example**
3996
3997```js
3998try {
3999    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4000    device.off('BLECharacteristicChange');
4001} catch (err) {
4002    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4003}
4004```
4005
4006
4007### on('BLEConnectionStateChange')<sup>(deprecated)</sup>
4008
4009on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
4010
4011Subscribes to the BLE connection state changes.
4012
4013> **NOTE**<br>
4014> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#on('BLEConnectionStateChange')](js-apis-bluetooth-ble.md#onbleconnectionstatechange).
4015
4016**Required permissions**: ohos.permission.USE_BLUETOOTH
4017
4018**System capability**: SystemCapability.Communication.Bluetooth.Core
4019
4020**Parameters**
4021
4022| Name     | Type                                      | Mandatory  | Description                                      |
4023| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
4024| type     | string                                   | Yes   | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
4025| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | Yes   | Callback invoked to return the BLE connection state.                          |
4026
4027**Example**
4028
4029```js
4030function ConnectStateChanged(state: bluetoothManager.BLEConnectChangedState) {
4031    console.log('bluetooth connect state changed');
4032    let connectState: bluetoothManager.ProfileConnectionState = state.state;
4033}
4034try {
4035    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4036    device.on('BLEConnectionStateChange', ConnectStateChanged);
4037} catch (err) {
4038    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4039}
4040```
4041
4042
4043### off('BLEConnectionStateChange')<sup>(deprecated)</sup>
4044
4045off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
4046
4047Unsubscribes from the BLE connection state changes.
4048
4049> **NOTE**<br>
4050> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#off('BLEConnectionStateChange')](js-apis-bluetooth-ble.md#offbleconnectionstatechange).
4051
4052**Required permissions**: ohos.permission.USE_BLUETOOTH
4053
4054**System capability**: SystemCapability.Communication.Bluetooth.Core
4055
4056**Parameters**
4057
4058| Name     | Type                                      | Mandatory  | Description                                      |
4059| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
4060| type     | string                                   | Yes   | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
4061| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | No   | Callback for the BLE connection state change event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
4062
4063**Example**
4064
4065```js
4066try {
4067    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4068    device.off('BLEConnectionStateChange');
4069} catch (err) {
4070    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4071}
4072```
4073
4074
4075### getDeviceName<sup>(deprecated)</sup>
4076
4077getDeviceName(callback: AsyncCallback&lt;string&gt;): void
4078
4079Obtains the name of the remote BLE device. This API uses an asynchronous callback to return the result.
4080
4081> **NOTE**<br>
4082> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getDeviceName](js-apis-bluetooth-ble.md#getdevicename).
4083
4084**Required permissions**: ohos.permission.USE_BLUETOOTH
4085
4086**System capability**: SystemCapability.Communication.Bluetooth.Core
4087
4088**Parameters**
4089
4090| Name     | Type                         | Mandatory  | Description                             |
4091| -------- | --------------------------- | ---- | ------------------------------- |
4092| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the remote BLE device name obtained.|
4093
4094**Error codes**
4095
4096For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
4097
4098| ID| Error Message|
4099| -------- | ---------------------------- |
4100|2900001 | Service stopped.                         |
4101|2900099 | Operation failed.                        |
4102
4103**Example**
4104
4105```js
4106// callback
4107try {
4108    let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
4109    gattClient.connect();
4110    let deviceName = gattClient.getDeviceName((err, data)=> {
4111        console.info('device name err ' + JSON.stringify(err));
4112        console.info('device name' + JSON.stringify(data));
4113    })
4114} catch (err) {
4115    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4116}
4117```
4118
4119
4120### getDeviceName<sup>(deprecated)</sup>
4121
4122getDeviceName(): Promise&lt;string&gt;
4123
4124Obtains the name of the remote BLE device. This API uses a promise to return the result.
4125
4126> **NOTE**<br>
4127> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getDeviceName](js-apis-bluetooth-ble.md#getdevicename-1).
4128
4129**Required permissions**: ohos.permission.USE_BLUETOOTH
4130
4131**System capability**: SystemCapability.Communication.Bluetooth.Core
4132
4133**Return value**
4134
4135| Type                   | Description                                |
4136| --------------------- | ---------------------------------- |
4137| Promise&lt;string&gt; | Promise used to return the remote BLE device name.|
4138
4139**Error codes**
4140
4141For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
4142
4143| ID| Error Message|
4144| -------- | ---------------------------- |
4145|2900001 | Service stopped.                         |
4146|2900099 | Operation failed.                        |
4147
4148**Example**
4149
4150```js
4151// promise
4152try {
4153    let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
4154    gattClient.connect();
4155    let deviceName = gattClient.getDeviceName().then((data) => {
4156        console.info('device name' + JSON.stringify(data));
4157    })
4158} catch (err) {
4159    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4160}
4161```
4162
4163
4164### getRssiValue<sup>(deprecated)</sup>
4165
4166getRssiValue(callback: AsyncCallback&lt;number&gt;): void
4167
4168Obtains the received signal strength indication (RSSI) of the remote BLE device. This API uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect).
4169
4170> **NOTE**<br>
4171> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getRssiValue](js-apis-bluetooth-ble.md#getrssivalue).
4172
4173**Required permissions**: ohos.permission.USE_BLUETOOTH
4174
4175**System capability**: SystemCapability.Communication.Bluetooth.Core
4176
4177**Parameters**
4178
4179| Name     | Type                         | Mandatory  | Description                            |
4180| -------- | --------------------------- | ---- | ------------------------------ |
4181| callback | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the RSSI, in dBm.|
4182
4183**Error codes**
4184
4185For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
4186
4187| ID| Error Message|
4188| -------- | ---------------------------- |
4189|2900099 | Operation failed.                        |
4190
4191**Example**
4192
4193```js
4194// callback
4195try {
4196    let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
4197    gattClient.connect();
4198    let rssi = gattClient.getRssiValue((err: BusinessError, data: number)=> {
4199        console.info('rssi err ' + JSON.stringify(err));
4200        console.info('rssi value' + JSON.stringify(data));
4201    })
4202} catch (err) {
4203    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4204}
4205```
4206
4207
4208### getRssiValue<sup>(deprecated)</sup>
4209
4210getRssiValue(): Promise&lt;number&gt;
4211
4212Obtains the RSSI of the remote BLE device. This API uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect).
4213
4214> **NOTE**<br>
4215> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattClientDevice#getRssiValue](js-apis-bluetooth-ble.md#getrssivalue-1).
4216
4217**Required permissions**: ohos.permission.USE_BLUETOOTH
4218
4219**System capability**: SystemCapability.Communication.Bluetooth.Core
4220
4221**Return value**
4222
4223| Type                   | Description                               |
4224| --------------------- | --------------------------------- |
4225| Promise&lt;number&gt; | Promise used to return the RSSI, in dBm.|
4226
4227**Error codes**
4228
4229For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
4230
4231| ID| Error Message|
4232| -------- | ---------------------------- |
4233|2900099 | Operation failed.                        |
4234
4235**Example**
4236
4237```js
4238// promise
4239try {
4240    let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
4241    let rssi = gattClient.getRssiValue().then((data: number) => {
4242        console.info('rssi' + JSON.stringify(data));
4243    })
4244} catch (err) {
4245    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4246}
4247```
4248
4249## ScanMode<sup>(deprecated)</sup><a name="ScanMode"></a>
4250
4251Enumerates the scan modes.
4252
4253> **NOTE**<br>
4254> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.ScanMode](js-apis-bluetooth-connection.md#scanmode).
4255
4256**System capability**: SystemCapability.Communication.Bluetooth.Core
4257
4258| Name                                      | Value | Description             |
4259| ---------------------------------------- | ---- | --------------- |
4260| SCAN_MODE_NONE                           | 0    | No scan mode.        |
4261| SCAN_MODE_CONNECTABLE                    | 1    | Connectable mode.       |
4262| SCAN_MODE_GENERAL_DISCOVERABLE           | 2    | General discoverable mode.   |
4263| SCAN_MODE_LIMITED_DISCOVERABLE           | 3    | Limited discoverable mode.   |
4264| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4    | General connectable and discoverable mode.|
4265| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5    | Limited connectable and discoverable mode.|
4266
4267## BondState<sup>(deprecated)</sup><a name="BondState"></a>
4268
4269Enumerates the pairing states.
4270
4271> **NOTE**<br>
4272> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.BondState](js-apis-bluetooth-connection.md#bondstate).
4273
4274**System capability**: SystemCapability.Communication.Bluetooth.Core
4275
4276| Name                | Value | Description    |
4277| ------------------ | ---- | ------ |
4278| BOND_STATE_INVALID | 0    | Invalid pairing.|
4279| BOND_STATE_BONDING | 1    | Pairing. |
4280| BOND_STATE_BONDED  | 2    | Paired.  |
4281
4282
4283## SppOption<sup>(deprecated)</sup><a name="SppOption"></a>
4284
4285Defines the SPP configuration parameters.
4286
4287> **NOTE**<br>
4288> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.SppOption](js-apis-bluetooth-socket.md#sppoptions).
4289
4290**System capability**: SystemCapability.Communication.Bluetooth.Core
4291
4292| Name    | Type               | Readable  | Writable  | Description         |
4293| ------ | ------------------- | ---- | ---- | ----------- |
4294| uuid   | string              | Yes   | Yes   | UUID of the SPP.|
4295| secure | boolean             | Yes   | Yes   | Whether it is a secure channel.   |
4296| type   | [SppType](#spptype) | Yes   | Yes   | Type of the SPP link.   |
4297
4298
4299## SppType<sup>(deprecated)</sup><a name="SppType"></a>
4300
4301Enumerates the SPP link types.
4302
4303> **NOTE**<br>
4304> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [socket.SppType](js-apis-bluetooth-socket.md#spptype).
4305
4306**System capability**: SystemCapability.Communication.Bluetooth.Core
4307
4308| Name        | Value | Description           |
4309| ---------- | ---- | ------------- |
4310| SPP_RFCOMM | 0    | Radio frequency communication (RFCOMM) link type.|
4311
4312
4313## GattService<sup>(deprecated)</sup>
4314
4315Defines the GATT service API parameters.
4316
4317> **NOTE**<br>
4318> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.GattService](js-apis-bluetooth-ble.md#gattservice).
4319
4320**System capability**: SystemCapability.Communication.Bluetooth.Core
4321
4322| Name             | Type                                    | Readable  | Writable  | Description                                      |
4323| --------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
4324| serviceUuid     | string                                   | Yes   | Yes   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4325| isPrimary       | boolean                                  | Yes   | Yes   | Whether the service is a primary service. The value **true** means a primary service.               |
4326| characteristics | Array&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes   | Yes   | List of characteristics of the service.                            |
4327| includeServices | Array&lt;[GattService](#gattservice)&gt; | Yes   | Yes   | Services on which the service depends.                            |
4328
4329
4330## BLECharacteristic<sup>(deprecated)</sup>
4331
4332Defines the characteristic API parameters.
4333
4334> **NOTE**<br>
4335> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.BLECharacteristic](js-apis-bluetooth-ble.md#blecharacteristic).
4336
4337**System capability**: SystemCapability.Communication.Bluetooth.Core
4338
4339| Name                 | Type                                    | Readable  | Writable  | Description                                |
4340| ------------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
4341| serviceUuid         | string                                   | Yes   | Yes   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4342| characteristicUuid  | string                                   | Yes   | Yes   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
4343| characteristicValue | ArrayBuffer                              | Yes   | Yes   | Binary value of the characteristic.                     |
4344| descriptors         | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes   | Yes   | List of descriptors of the characteristic.               |
4345
4346
4347## BLEDescriptor<sup>(deprecated)</sup>
4348
4349Defines the descriptor API parameters.
4350
4351> **NOTE**<br>
4352> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.BLEDescriptor](js-apis-bluetooth-ble.md#bledescriptor).
4353
4354**System capability**: SystemCapability.Communication.Bluetooth.Core
4355
4356| Name                | Type       | Readable  | Writable  | Description                                      |
4357| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
4358| serviceUuid        | string      | Yes   | Yes   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4359| characteristicUuid | string      | Yes   | Yes   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
4360| descriptorUuid     | string      | Yes   | Yes   | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
4361| descriptorValue    | ArrayBuffer | Yes   | Yes   | Binary value of the descriptor.                             |
4362
4363
4364## NotifyCharacteristic<sup>(deprecated)</sup>
4365
4366Defines the parameters in the notifications sent when the server characteristic value changes.
4367
4368> **NOTE**<br>
4369> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.NotifyCharacteristic](js-apis-bluetooth-ble.md#notifycharacteristic).
4370
4371**System capability**: SystemCapability.Communication.Bluetooth.Core
4372
4373| Name                 | Type       | Readable  | Writable  | Description                                      |
4374| ------------------- | ----------- | ---- | ---- | ---------------------------------------- |
4375| serviceUuid         | string      | Yes   | Yes   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4376| characteristicUuid  | string      | Yes   | Yes   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
4377| characteristicValue | ArrayBuffer | Yes   | Yes   | Binary value of the characteristic.                              |
4378| confirm             | boolean     | Yes   | Yes   | Whether the notification needs to be confirmed by the remote end. For a notification, set it to **true**. In this case, the remote end must confirm the receipt of the notification. For an indication, set it to **false**. In this case, the remote end does not need to confirm the receipt of the notification.|
4379
4380
4381## CharacteristicReadRequest<sup>(deprecated)</sup>
4382
4383Defines the parameters of the **CharacteristicReadReq** event received by the server.
4384
4385> **NOTE**<br>
4386> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.CharacteristicReadRequest](js-apis-bluetooth-ble.md#characteristicreadrequest).
4387
4388**System capability**: SystemCapability.Communication.Bluetooth.Core
4389
4390| Name                | Type  | Readable  | Writable  | Description                                      |
4391| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
4392| deviceId           | string | Yes   | No   | Address of the remote device that sends the **CharacteristicReadReq** event, for example, XX:XX:XX:XX:XX:XX.|
4393| transId            | number | Yes   | No   | Transmission ID of the read request. The response returned by the server must use the same transmission ID.      |
4394| offset             | number | Yes   | No   | Position from which the characteristic value is read. For example, **k** means to read from the kth byte. The response returned by the server must use the same offset.|
4395| characteristicUuid | string | Yes   | No   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
4396| serviceUuid        | string | Yes   | No   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4397
4398
4399## CharacteristicWriteRequest<sup>(deprecated)</sup>
4400
4401Defines the parameters of the **CharacteristicWriteReq** event received by the server.
4402
4403> **NOTE**<br>
4404> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.CharacteristicWriteRequest](js-apis-bluetooth-ble.md#characteristicwriterequest).
4405
4406**System capability**: SystemCapability.Communication.Bluetooth.Core
4407
4408| Name                | Type  | Readable  | Writable  | Description                                      |
4409| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
4410| deviceId           | string | Yes   | No   | Address of the remote device that sends the **CharacteristicWriteReq** event, for example, XX:XX:XX:XX:XX:XX.|
4411| transId            | number | Yes   | No   | Transmission ID of the write request. The response returned by the server must use the same transmission ID.      |
4412| offset             | number | Yes   | No   | Start position for writing the characteristic value. For example, **k** means to write from the kth byte. The response returned by the server must use the same offset.|
4413| descriptorUuid     | string | Yes   | No   | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
4414| characteristicUuid | string | Yes   | No   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
4415| serviceUuid        | string | Yes   | No   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4416
4417
4418## DescriptorReadRequest<sup>(deprecated)</sup>
4419
4420Defines the parameters of the **DescriptorReadReq** event received by the server.
4421
4422> **NOTE**<br>
4423> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.DescriptorReadRequest](js-apis-bluetooth-ble.md#descriptorreadrequest).
4424
4425**System capability**: SystemCapability.Communication.Bluetooth.Core
4426
4427| Name                | Type  | Readable  | Writable  | Description                                      |
4428| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
4429| deviceId           | string | Yes   | No   | Address of the remote device that sends a **DescriptorReadReq** event, for example, XX:XX:XX:XX:XX:XX.|
4430| transId            | number | Yes   | No   | Transmission ID of the read request. The response returned by the server must use the same transmission ID.      |
4431| offset             | number | Yes   | No   | Position from which the descriptor is read. For example, **k** means to read from the kth byte. The response returned by the server must use the same offset.|
4432| descriptorUuid     | string | Yes   | No   | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
4433| characteristicUuid | string | Yes   | No   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
4434| serviceUuid        | string | Yes   | No   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4435
4436
4437## DescriptorWriteRequest<sup>(deprecated)</sup>
4438
4439Defines the parameters of the **DescriptorWriteReq** event received by the server.
4440
4441> **NOTE**<br>
4442> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.DescriptorWriteRequest](js-apis-bluetooth-ble.md#descriptorwriterequest).
4443
4444**System capability**: SystemCapability.Communication.Bluetooth.Core
4445
4446| Name                | Type       | Readable  | Writable  | Description                                      |
4447| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
4448| deviceId           | string      | Yes   | No   | Address of the remote device that sends a **DescriptorWriteReq** event, for example, XX:XX:XX:XX:XX:XX.|
4449| transId            | number      | Yes   | No   | Transmission ID of the write request. The response returned by the server must use the same transmission ID.      |
4450| offset             | number      | Yes   | No   | Start position for writing the descriptor. For example, **k** means to write from the kth byte. The response returned by the server must use the same offset.|
4451| isPrep             | boolean     | Yes   | No   | Whether the write request is executed immediately.                            |
4452| needRsp            | boolean     | Yes   | No   | Whether to send a response to the GATT client.                      |
4453| value              | ArrayBuffer | Yes   | No   | Binary value of the descriptor to write.                          |
4454| descriptorUuid     | string      | Yes   | No   | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
4455| characteristicUuid | string      | Yes   | No   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
4456| serviceUuid        | string      | Yes   | No   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4457
4458
4459## ServerResponse<sup>(deprecated)</sup>
4460
4461Defines the parameters of the server's response to the GATT client's read/write request.
4462
4463> **NOTE**<br>
4464> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ServerResponse](js-apis-bluetooth-ble.md#serverresponse).
4465
4466**System capability**: SystemCapability.Communication.Bluetooth.Core
4467
4468| Name      | Type       | Readable  | Writable  | Description                                    |
4469| -------- | ----------- | ---- | ---- | -------------------------------------- |
4470| deviceId | string      | Yes   | No   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.      |
4471| transId  | number      | Yes   | No   | Transmission ID of the request. The value must be the same as the ID carried in the read/write request received.       |
4472| status   | number      | Yes   | No   | Response state. Set this parameter to **0**, which indicates a normal response.                  |
4473| offset   | number      | Yes   | No   | Start read/write position. The value must be the same as the offset carried in the read/write request.|
4474| value    | ArrayBuffer | Yes   | No   | Binary data in the response.                         |
4475
4476
4477## BLEConnectChangedState<sup>(deprecated)</sup>
4478
4479Defines the parameters of **BLEConnectChangedState**.
4480
4481> **NOTE**<br>
4482> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [BLEConnectionChangeState](js-apis-bluetooth-ble.md#bleconnectionchangestate).
4483
4484**System capability**: SystemCapability.Communication.Bluetooth.Core
4485
4486| Name    | Type                                         | Readable| Writable| Description                                         |
4487| -------- | ------------------------------------------------- | ---- | ---- | --------------------------------------------- |
4488| deviceId | string                                            | Yes  | No  | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
4489| state    | [ProfileConnectionState](#profileconnectionstate) | Yes  | Yes  | BLE connection state.                      |
4490
4491
4492## ProfileConnectionState<sup>(deprecated)</sup>
4493
4494Enumerates the profile connection states.
4495
4496> **NOTE**<br>
4497> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [constant.ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate).
4498
4499**System capability**: SystemCapability.Communication.Bluetooth.Core
4500
4501| Name                 | Value | Description            |
4502| ------------------- | ---- | -------------- |
4503| STATE_DISCONNECTED  | 0    | Disconnected. |
4504| STATE_CONNECTING    | 1    | Connecting.|
4505| STATE_CONNECTED     | 2    | Connected. |
4506| STATE_DISCONNECTING | 3    | Disconnecting.|
4507
4508
4509## ScanFilter<sup>(deprecated)</sup>
4510
4511Defines the scan filter parameters.
4512
4513> **NOTE**<br>
4514> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ScanFilter](js-apis-bluetooth-ble.md#scanfilter).
4515
4516**System capability**: SystemCapability.Communication.Bluetooth.Core
4517
4518| Name                                    | Type   | Readable| Writable| Description                                                        |
4519| ---------------------------------------- | ----------- | ---- | ---- | ------------------------------------------------------------ |
4520| deviceId                                 | string      | Yes  | Yes  | Address of the BLE device to filter, for example, XX:XX:XX:XX:XX:XX.          |
4521| name                                     | string      | Yes  | Yes  | Name of the BLE device to filter.                                       |
4522| serviceUuid                              | string      | Yes  | Yes  | Service UUID of the device to filter, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
4523| serviceUuidMask             | string      | Yes  | Yes  | Service UUID mask of the device to filter, for example, **FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF**.|
4524| serviceSolicitationUuid     | string      | Yes  | Yes  | Service solicitation UUID of the device to filter, for example, **00001888-0000-1000-8000-00805F9B34FB**.|
4525| serviceSolicitationUuidMask | string      | Yes  | Yes  | Service solicitation UUID mask of the device to filter, for example, **FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF**.|
4526| serviceData                 | ArrayBuffer | Yes  | Yes  | Service data of the device to filter, for example, **[0x90, 0x00, 0xF1, 0xF2]**.|
4527| serviceDataMask             | ArrayBuffer | Yes  | Yes  | Service data mask of the device to filter, for example, **[0xFF,0xFF,0xFF,0xFF]**.|
4528| manufactureId               | number      | Yes  | Yes  | Manufacturer ID of the device to filter, for example, **0x0006**.                |
4529| manufactureData             | ArrayBuffer | Yes  | Yes  | Manufacturer data of the device to filter, for example, **[0x1F,0x2F,0x3F]**.|
4530| manufactureDataMask         | ArrayBuffer | Yes  | Yes  | Manufacturer data mask of the device to filter, for example, **[0xFF, 0xFF, 0xFF]**.|
4531
4532
4533## ScanOptions<sup>(deprecated)</sup>
4534
4535Defines the scan configuration parameters.
4536
4537> **NOTE**<br>
4538> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ScanOptions](js-apis-bluetooth-ble.md#scanoptions).
4539
4540**System capability**: SystemCapability.Communication.Bluetooth.Core
4541
4542| Name       | Type                   | Readable  | Writable  | Description                                    |
4543| --------- | ----------------------- | ---- | ---- | -------------------------------------- |
4544| interval  | number                  | Yes   | Yes   | Delay in reporting the scan result. The default value is **0**.                   |
4545| dutyMode  | [ScanDuty](#scanduty)   | Yes   | Yes   | Scan duty. The default value is SCAN_MODE_LOW_POWER.       |
4546| matchMode | [MatchMode](#matchmode) | Yes   | Yes   | Hardware filtering match mode. The default value is **MATCH_MODE_AGGRESSIVE**.|
4547
4548
4549## ScanDuty<sup>(deprecated)</sup>
4550
4551Enumerates the scan duty options.
4552
4553> **NOTE**<br>
4554> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ScanDuty](js-apis-bluetooth-ble.md#scanduty).
4555
4556**System capability**: SystemCapability.Communication.Bluetooth.Core
4557
4558| Name                   | Value | Description          |
4559| --------------------- | ---- | ------------ |
4560| SCAN_MODE_LOW_POWER   | 0    | Low-power mode, which is the default value.|
4561| SCAN_MODE_BALANCED    | 1    | Balanced mode.     |
4562| SCAN_MODE_LOW_LATENCY | 2    | Low-latency mode.    |
4563
4564
4565## MatchMode<sup>(deprecated)</sup>
4566
4567Enumerates the hardware match modes of BLE scan filters.
4568
4569> **NOTE**<br>
4570> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.MatchMode](js-apis-bluetooth-ble.md#matchmode).
4571
4572**System capability**: SystemCapability.Communication.Bluetooth.Core
4573
4574| Name                   | Value | Description                                      |
4575| --------------------- | ---- | ---------------------------------------- |
4576| MATCH_MODE_AGGRESSIVE | 1    | Hardware reports the scan result with a lower threshold of signal strength and few number of matches in a duration. This is the default value.|
4577| MATCH_MODE_STICKY     | 2    | Hardware reports the scan result with a higher threshold of signal strength and sightings.      |
4578
4579
4580## ScanResult<sup>(deprecated)</sup>
4581
4582Defines the scan result.
4583
4584> **NOTE**<br>
4585> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ScanResult](js-apis-bluetooth-ble.md#scanresult).
4586
4587**System capability**: SystemCapability.Communication.Bluetooth.Core
4588
4589| Name      | Type       | Readable  | Writable  | Description                                |
4590| -------- | ----------- | ---- | ---- | ---------------------------------- |
4591| deviceId | string      | Yes   | No   | Address of the scanned device, for example, XX:XX:XX:XX:XX:XX.|
4592| rssi     | number      | Yes   | No   | RSSI of the device.                   |
4593| data     | ArrayBuffer | Yes   | No   | Advertisement packets sent by the device.                   |
4594
4595
4596## BluetoothState<sup>(deprecated)</sup>
4597
4598Enumerates the Bluetooth states.
4599
4600> **NOTE**<br>
4601> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [access.BluetoothState](js-apis-bluetooth-access.md#bluetoothstate).
4602
4603**System capability**: SystemCapability.Communication.Bluetooth.Core
4604
4605| Name                   | Value | Description                |
4606| --------------------- | ---- | ------------------ |
4607| STATE_OFF             | 0    | Bluetooth is turned off.          |
4608| STATE_TURNING_ON      | 1    | Bluetooth is being turned on.         |
4609| STATE_ON              | 2    | Bluetooth is turned on.          |
4610| STATE_TURNING_OFF     | 3    | Bluetooth is being turned off.         |
4611| STATE_BLE_TURNING_ON  | 4    | The LE-only mode is being turned on for Bluetooth.|
4612| STATE_BLE_ON          | 5    | Bluetooth is in LE-only mode. |
4613| STATE_BLE_TURNING_OFF | 6    | The LE-only mode is being turned off for Bluetooth.|
4614
4615
4616## AdvertiseSetting<sup>(deprecated)</sup>
4617
4618Defines the BLE advertising parameters.
4619
4620> **NOTE**<br>
4621> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.AdvertiseSetting](js-apis-bluetooth-ble.md#advertisesetting).
4622
4623**System capability**: SystemCapability.Communication.Bluetooth.Core
4624
4625| Name         | Type   | Readable  | Writable  | Description                                      |
4626| ----------- | ------- | ---- | ---- | ---------------------------------------- |
4627| interval    | number  | Yes   | Yes   | Interval for BLE advertising. The minimum value is **32** slots (20 ms). The maximum value is **16384** slots. The default value is **1600** slots (1s).|
4628| txPower     | number  | Yes   | Yes   | Transmit power, in dBm. The value range is -127 to 1. The default value is **-7**.  |
4629| connectable | boolean | Yes   | Yes   | Whether the advertisement is connectable. The default value is **true**.                  |
4630
4631
4632## AdvertiseData<sup>(deprecated)</sup>
4633
4634Defines the content of a BLE advertisement packet.
4635
4636> **NOTE**<br>
4637> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.AdvertiseData](js-apis-bluetooth-ble.md#advertisedata).
4638
4639**System capability**: SystemCapability.Communication.Bluetooth.Core
4640
4641| Name             | Type                                    | Readable  | Writable  | Description                         |
4642| --------------- | ---------------------------------------- | ---- | ---- | --------------------------- |
4643| serviceUuids    | Array&lt;string&gt;                      | Yes   | Yes   | List of service UUIDs to broadcast.|
4644| manufactureData | Array&lt;[ManufactureData](#manufacturedata)&gt; | Yes   | Yes   | List of manufacturers to broadcast.          |
4645| serviceData     | Array&lt;[ServiceData](#servicedata)&gt; | Yes   | Yes   | List of service data to broadcast.              |
4646
4647
4648## ManufactureData<sup>(deprecated)</sup>
4649
4650Defines the content of a BLE advertisement packet.
4651
4652> **NOTE**<br>
4653> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ManufactureData](js-apis-bluetooth-ble.md#manufacturedata).
4654
4655**System capability**: SystemCapability.Communication.Bluetooth.Core
4656
4657| Name              | Type               | Readable  | Writable  | Description                |
4658| ---------------- | ------------------- | ---- | ---- | ------------------ |
4659| manufactureId    | number  | Yes   | Yes   | Manufacturer ID allocated by the Bluetooth SIG.|
4660| manufactureValue | ArrayBuffer         | Yes   | Yes   | Manufacturer data.    |
4661
4662
4663## ServiceData<sup>(deprecated)</sup>
4664
4665Defines the service data contained in an advertisement packet.
4666
4667> **NOTE**<br>
4668> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [ble.ServiceData](js-apis-bluetooth-ble.md#servicedata).
4669
4670**System capability**: SystemCapability.Communication.Bluetooth.Core
4671
4672| Name          | Type       | Readable  | Writable  | Description        |
4673| ------------ | ----------- | ---- | ---- | ---------- |
4674| serviceUuid  | string      | Yes   | Yes   | Service UUID.|
4675| serviceValue | ArrayBuffer | Yes   | Yes   | Service data.   |
4676
4677
4678## PinRequiredParam<sup>(deprecated)</sup><a name="PinRequiredParam"></a>
4679
4680Defines the pairing request parameters.
4681
4682> **NOTE**<br>
4683> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.PinRequiredParam](js-apis-bluetooth-connection.md#pinrequiredparam).
4684
4685**System capability**: SystemCapability.Communication.Bluetooth.Core
4686
4687| Name      | Type  | Readable  | Writable  | Description         |
4688| -------- | ------ | ---- | ---- | ----------- |
4689| deviceId | string | Yes   | No   | ID of the device to pair.|
4690| pinCode  | string | Yes   | No   | Key for the device pairing.  |
4691
4692
4693## BondStateParam<sup>(deprecated)</sup><a name="BondStateParam"></a>
4694
4695Defines the pairing state parameters.
4696
4697> **NOTE**<br>
4698> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.BondStateParam](js-apis-bluetooth-connection.md#bondstateparam).
4699
4700**System capability**: SystemCapability.Communication.Bluetooth.Core
4701
4702| Name      | Type  | Readable  | Writable  | Description         |
4703| -------- | ------ | ---- | ---- | ----------- |
4704| deviceId | string      | Yes   | No   | ID of the device to pair.|
4705| state    | BondState   | Yes   | No   | State of the device.|
4706
4707
4708## StateChangeParam<sup>(deprecated)</sup><a name="StateChangeParam"></a>
4709
4710Defines the profile state change parameters.
4711
4712> **NOTE**<br>
4713> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [baseProfile.StateChangeParam](js-apis-bluetooth-baseProfile.md#statechangeparam).
4714
4715**System capability**: SystemCapability.Communication.Bluetooth.Core
4716
4717| Name    | Type                                         | Readable| Writable| Description                           |
4718| -------- | ------------------------------------------------- | ---- | ---- | ------------------------------- |
4719| deviceId | string                                            | Yes  | No  | Address of a Bluetooth device.             |
4720| state    | [ProfileConnectionState](#profileconnectionstate) | Yes  | No  | Profile connection state of the device.|
4721
4722
4723## DeviceClass<sup>(deprecated)</sup><a name="DeviceClass"></a>
4724
4725Defines the class of a Bluetooth device.
4726
4727> **NOTE**<br>
4728> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [connection.DeviceClass](js-apis-bluetooth-connection.md#deviceclass).
4729
4730**System capability**: SystemCapability.Communication.Bluetooth.Core
4731
4732| Name             | Type                               | Readable  | Writable  | Description              |
4733| --------------- | ----------------------------------- | ---- | ---- | ---------------- |
4734| majorClass      | [MajorClass](#majorclass)           | Yes   | No   | Major classes of Bluetooth devices.  |
4735| majorMinorClass | [MajorMinorClass](#majorminorclass) | Yes   | No   | Major and minor classes of Bluetooth devices.|
4736| classOfDevice   | number                              | Yes   | No   | Class of the device.         |
4737
4738
4739## MajorClass<sup>(deprecated)</sup><a name="MajorClass"></a>
4740
4741Enumerates the major classes of Bluetooth devices.
4742
4743> **NOTE**<br>
4744> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [constant.MajorClass](js-apis-bluetooth-constant.md#majorclass).
4745
4746**System capability**: SystemCapability.Communication.Bluetooth.Core
4747
4748| Name                 | Value   | Description        |
4749| ------------------- | ------ | ---------- |
4750| MAJOR_MISC          | 0x0000 | Miscellaneous device.   |
4751| MAJOR_COMPUTER      | 0x0100 | Computer.  |
4752| MAJOR_PHONE         | 0x0200 | Mobile phone.   |
4753| MAJOR_NETWORKING    | 0x0300 | Network device.   |
4754| MAJOR_AUDIO_VIDEO   | 0x0400 | Audio or video device.|
4755| MAJOR_PERIPHERAL    | 0x0500 | Peripheral device.   |
4756| MAJOR_IMAGING       | 0x0600 | Imaging device.   |
4757| MAJOR_WEARABLE      | 0x0700 | Wearable device.  |
4758| MAJOR_TOY           | 0x0800 | Toy.   |
4759| MAJOR_HEALTH        | 0x0900 | Health device.   |
4760| MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device.  |
4761
4762
4763## MajorMinorClass<sup>(deprecated)</sup><a name="MajorMinorClass"></a>
4764
4765Enumerates the major and minor classes of Bluetooth devices.
4766
4767> **NOTE**<br>
4768> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [constant.MajorMinorClass](js-apis-bluetooth-constant.md#majorminorclass).
4769
4770**System capability**: SystemCapability.Communication.Bluetooth.Core
4771
4772| Name                                      | Value   | Description             |
4773| ---------------------------------------- | ------ | --------------- |
4774| COMPUTER_UNCATEGORIZED                   | 0x0100 | Unclassified computer.    |
4775| COMPUTER_DESKTOP                         | 0x0104 | Desktop computer.     |
4776| COMPUTER_SERVER                          | 0x0108 | Server.       |
4777| COMPUTER_LAPTOP                          | 0x010C | Laptop.    |
4778| COMPUTER_HANDHELD_PC_PDA                 | 0x0110 | Hand-held computer.    |
4779| COMPUTER_PALM_SIZE_PC_PDA                | 0x0114 | Palmtop computer.      |
4780| COMPUTER_WEARABLE                        | 0x0118 | Wearable computer.    |
4781| COMPUTER_TABLET                          | 0x011C | Tablet.      |
4782| PHONE_UNCATEGORIZED                      | 0x0200 | Unclassified mobile phone.     |
4783| PHONE_CELLULAR                           | 0x0204 | Portable phone.     |
4784| PHONE_CORDLESS                           | 0x0208 | Cordless phone.      |
4785| PHONE_SMART                              | 0x020C | Smartphone.      |
4786| PHONE_MODEM_OR_GATEWAY                   | 0x0210 | Modem or gateway phone.|
4787| PHONE_ISDN                               | 0x0214 | ISDN phone.    |
4788| NETWORK_FULLY_AVAILABLE                  | 0x0300 | Device with network fully available.    |
4789| NETWORK_1_TO_17_UTILIZED                 | 0x0320 | Device used on network 1 to 17.  |
4790| NETWORK_17_TO_33_UTILIZED                | 0x0340 | Device used on network 17 to 33. |
4791| NETWORK_33_TO_50_UTILIZED                | 0x0360 | Device used on network 33 to 50. |
4792| NETWORK_60_TO_67_UTILIZED                | 0x0380 | Device used on network 60 to 67. |
4793| NETWORK_67_TO_83_UTILIZED                | 0x03A0 | Device used on network 67 to 83. |
4794| NETWORK_83_TO_99_UTILIZED                | 0x03C0 | Device used on network 83 to 99. |
4795| NETWORK_NO_SERVICE                       | 0x03E0 | Device without network service     |
4796| AUDIO_VIDEO_UNCATEGORIZED                | 0x0400 | Unclassified audio or video device.   |
4797| AUDIO_VIDEO_WEARABLE_HEADSET             | 0x0404 | Wearable audio or video headset.  |
4798| AUDIO_VIDEO_HANDSFREE                    | 0x0408 | Hands-free audio or video device.    |
4799| AUDIO_VIDEO_MICROPHONE                   | 0x0410 | Audio or video microphone.   |
4800| AUDIO_VIDEO_LOUDSPEAKER                  | 0x0414 | Audio or video loudspeaker.   |
4801| AUDIO_VIDEO_HEADPHONES                   | 0x0418 | Audio or video headphones.   |
4802| AUDIO_VIDEO_PORTABLE_AUDIO               | 0x041C | Portable audio or video device.   |
4803| AUDIO_VIDEO_CAR_AUDIO                    | 0x0420 | In-vehicle audio or video device.    |
4804| AUDIO_VIDEO_SET_TOP_BOX                  | 0x0424 | Audio or video STB device.   |
4805| AUDIO_VIDEO_HIFI_AUDIO                   | 0x0428 | High-fidelity speaker device.     |
4806| AUDIO_VIDEO_VCR                          | 0x042C | Video cassette recording (VCR) device.   |
4807| AUDIO_VIDEO_VIDEO_CAMERA                 | 0x0430 | Camera.   |
4808| AUDIO_VIDEO_CAMCORDER                    | 0x0434 | Camcorder   |
4809| AUDIO_VIDEO_VIDEO_MONITOR                | 0x0438 | Audio or video monitor.   |
4810| AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER | 0x043C | Video display or loudspeaker. |
4811| AUDIO_VIDEO_VIDEO_CONFERENCING           | 0x0440 | Video conferencing device.    |
4812| AUDIO_VIDEO_VIDEO_GAMING_TOY             | 0x0448 | Audio or video gaming toy.  |
4813| PERIPHERAL_NON_KEYBOARD_NON_POINTING     | 0x0500 | Non-keyboard or non-pointing peripheral device.  |
4814| PERIPHERAL_KEYBOARD                      | 0x0540 | Keyboard device.      |
4815| PERIPHERAL_POINTING_DEVICE               | 0x0580 | Pointing peripheral device.    |
4816| PERIPHERAL_KEYBOARD_POINTING             | 0x05C0 | Keyboard pointing device.    |
4817| PERIPHERAL_UNCATEGORIZED                 | 0x0500 | Unclassified peripheral device.     |
4818| PERIPHERAL_JOYSTICK                      | 0x0504 | Peripheral joystick.     |
4819| PERIPHERAL_GAMEPAD                       | 0x0508 | Peripheral game pad     |
4820| PERIPHERAL_REMOTE_CONTROL                | 0x05C0 | Peripheral remote control device    |
4821| PERIPHERAL_SENSING_DEVICE                | 0x0510 | Peripheral sensing device.    |
4822| PERIPHERAL_DIGITIZER_TABLET              | 0x0514 | Peripheral digitizer tablet.|
4823| PERIPHERAL_CARD_READER                   | 0x0518 | Peripheral card reader.     |
4824| PERIPHERAL_DIGITAL_PEN                   | 0x051C | Peripheral digital pen.     |
4825| PERIPHERAL_SCANNER_RFID                  | 0x0520 | Peripheral RFID scanner. |
4826| PERIPHERAL_GESTURAL_INPUT                | 0x0522 | Gesture input device.    |
4827| IMAGING_UNCATEGORIZED                    | 0x0600 | Unclassified imaging device.    |
4828| IMAGING_DISPLAY                          | 0x0610 | Imaging display device.      |
4829| IMAGING_CAMERA                           | 0x0620 | Imaging camera device.     |
4830| IMAGING_SCANNER                          | 0x0640 | Imaging scanner.     |
4831| IMAGING_PRINTER                          | 0x0680 | Imaging printer.     |
4832| WEARABLE_UNCATEGORIZED                   | 0x0700 | Unclassified wearable device.   |
4833| WEARABLE_WRIST_WATCH                     | 0x0704 | Smart watch.     |
4834| WEARABLE_PAGER                           | 0x0708 | Wearable pager.    |
4835| WEARABLE_JACKET                          | 0x070C | Smart jacket.     |
4836| WEARABLE_HELMET                          | 0x0710 | Wearable helmet.     |
4837| WEARABLE_GLASSES                         | 0x0714 | Wearable glasses.     |
4838| TOY_UNCATEGORIZED                        | 0x0800 | Unclassified toy.    |
4839| TOY_ROBOT                                | 0x0804 | Toy robot.     |
4840| TOY_VEHICLE                              | 0x0808 | Toy vehicle.       |
4841| TOY_DOLL_ACTION_FIGURE                   | 0x080C | Humanoid toy doll.    |
4842| TOY_CONTROLLER                           | 0x0810 | Toy controller.     |
4843| TOY_GAME                                 | 0x0814 | Toy gaming device.      |
4844| HEALTH_UNCATEGORIZED                     | 0x0900 | Unclassified health devices.     |
4845| HEALTH_BLOOD_PRESSURE                    | 0x0904 | Blood pressure device.      |
4846| HEALTH_THERMOMETER                       | 0x0908 | Thermometer     |
4847| HEALTH_WEIGHING                          | 0x090C | Body scale.      |
4848| HEALTH_GLUCOSE                           | 0x0910 | Blood glucose monitor.     |
4849| HEALTH_PULSE_OXIMETER                    | 0x0914 | Pulse oximeter.   |
4850| HEALTH_PULSE_RATE                        | 0x0918 | Heart rate monitor.     |
4851| HEALTH_DATA_DISPLAY                      | 0x091C | Health data display.    |
4852| HEALTH_STEP_COUNTER                      | 0x0920 | Step counter.   |
4853| HEALTH_BODY_COMPOSITION_ANALYZER         | 0x0924 | Body composition analyzer. |
4854| HEALTH_PEAK_FLOW_MONITOR                  | 0x0928 | Hygrometer.     |
4855| HEALTH_MEDICATION_MONITOR                | 0x092C | Medication monitor.   |
4856| HEALTH_KNEE_PROSTHESIS                   | 0x0930 | Prosthetic knee.    |
4857| HEALTH_ANKLE_PROSTHESIS                  | 0x0934 | Prosthetic ankle.    |
4858| HEALTH_GENERIC_HEALTH_MANAGER            | 0x0938 | Generic health management device.    |
4859| HEALTH_PERSONAL_MOBILITY_DEVICE          | 0x093C | Personal mobility device.    |
4860
4861
4862## PlayingState<sup>(deprecated)</sup><a name="PlayingState"></a>
4863
4864Enumerates the A2DP playing states.
4865
4866> **NOTE**<br>
4867> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [a2dp.PlayingState](js-apis-bluetooth-a2dp.md#playingstate).
4868
4869**System capability**: SystemCapability.Communication.Bluetooth.Core
4870
4871| Name               | Value   | Description     |
4872| ----------------- | ------ | ------- |
4873| STATE_NOT_PLAYING | 0x0000 | Not playing. |
4874| STATE_PLAYING     | 0x0001 | Playing.|
4875
4876
4877## ProfileId<sup>(deprecated)</sup><a name="ProfileId"></a>
4878
4879Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOST** and **PROFILE_PAN_NETWORK**.
4880
4881> **NOTE**<br>
4882> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [constant.ProfileId](js-apis-bluetooth-constant.md#profileid).
4883
4884**System capability**: SystemCapability.Communication.Bluetooth.Core
4885
4886| Name                              | Value   | Description             |
4887| -------------------------------- | ------ | --------------- |
4888| PROFILE_A2DP_SOURCE              | 1 | A2DP profile.|
4889| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | HFP profile. |
4890| PROFILE_HID_HOST | 6 | Human Interface Device (HID) profile. |
4891| PROFILE_PAN_NETWORK | 7 | PAN profile. |
4892