• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bluetooth (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 7. 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 9. 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 bluetooth from '@ohos.bluetooth';
16```
17
18
19## bluetooth.enableBluetooth<sup>8+</sup><sup>(deprecated)</sup><a name="enableBluetooth"></a>
20
21enableBluetooth(): boolean
22
23Enables Bluetooth.
24
25> **NOTE**<br>
26> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.enableBluetooth](js-apis-bluetoothManager.md#bluetoothmanagerenablebluetoothdeprecated).
27
28**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
29
30**System capability**: SystemCapability.Communication.Bluetooth.Core
31
32**Return value**
33
34| Type     | Description                      |
35| ------- | ------------------------ |
36| boolean | Returns **true** if Bluetooth is enabled; returns **false** otherwise.|
37
38**Example**
39
40```js
41let enable : boolean = bluetooth.enableBluetooth();
42```
43
44
45## bluetooth.disableBluetooth<sup>8+</sup><sup>(deprecated)</sup><a name="disableBluetooth"></a>
46
47disableBluetooth(): boolean
48
49Disables Bluetooth.
50
51> **NOTE**<br>
52> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.disableBluetooth](js-apis-bluetoothManager.md#bluetoothmanagerdisablebluetoothdeprecated).
53
54**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
55
56**System capability**: SystemCapability.Communication.Bluetooth.Core
57
58**Return value**
59
60| Type     | Description                      |
61| ------- | ------------------------ |
62| boolean | Returns **true** if Bluetooth is disabled; returns **false** otherwise.|
63
64**Example**
65
66```js
67let disable : boolean = bluetooth.disableBluetooth();
68```
69
70
71## bluetooth.getLocalName<sup>8+</sup><sup>(deprecated)</sup><a name="getLocalName"></a>
72
73getLocalName(): string
74
75Obtains the name of the local Bluetooth device.
76
77> **NOTE**<br>
78> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getLocalName](js-apis-bluetoothManager.md#bluetoothmanagergetlocalnamedeprecated).
79
80**Required permissions**: ohos.permission.USE_BLUETOOTH
81
82**System capability**: SystemCapability.Communication.Bluetooth.Core
83
84**Return value**
85
86| Type    | Description       |
87| ------ | --------- |
88| string | Name of the local Bluetooth device obtained.|
89
90**Example**
91
92```js
93let localName : string = bluetooth.getLocalName();
94```
95
96
97## bluetooth.getState<sup>(deprecated)</sup><a name="getState"></a>
98
99getState(): BluetoothState
100
101Obtains the Bluetooth state.
102
103> **NOTE**<br>
104> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.getState](js-apis-bluetoothManager.md#bluetoothmanagergetstatedeprecated).
105
106**Required permissions**: ohos.permission.USE_BLUETOOTH
107
108**System capability**: SystemCapability.Communication.Bluetooth.Core
109
110**Return value**
111
112| Type                               | Description       |
113| --------------------------------- | --------- |
114| [BluetoothState](#bluetoothstate) | Bluetooth state obtained.|
115
116**Example**
117
118```js
119let state : bluetooth.BluetoothState = bluetooth.getState();
120```
121
122
123## bluetooth.getBtConnectionState<sup>(deprecated)</sup><a name="getBtConnectionState"></a>
124
125getBtConnectionState(): ProfileConnectionState
126
127Obtains the local profile connection state.
128
129> **NOTE**<br>
130> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.getBtConnectionState](js-apis-bluetoothManager.md#bluetoothmanagergetbtconnectionstatedeprecated).
131
132**Required permissions**: ohos.permission.USE_BLUETOOTH
133
134**System capability**: SystemCapability.Communication.Bluetooth.Core
135
136**Return value**
137
138| Type                                      | Description                 |
139| ---------------------------------------- | ------------------- |
140| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
141
142**Example**
143
144```js
145let connectionState : bluetooth.ProfileConnectionState = bluetooth.getBtConnectionState();
146```
147
148
149## bluetooth.setLocalName<sup>8+</sup><sup>(deprecated)</sup><a name="setLocalName"></a>
150
151setLocalName(name: string): boolean
152
153Sets the name of the local Bluetooth device.
154
155> **NOTE**<br>
156> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.setLocalName](js-apis-bluetoothManager.md#bluetoothmanagersetlocalnamedeprecated).
157
158**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
159
160**System capability**: SystemCapability.Communication.Bluetooth.Core
161
162**Parameters**
163
164| Name | Type    | Mandatory  | Description                   |
165| ---- | ------ | ---- | --------------------- |
166| name | string | Yes   | Bluetooth device name to set. It cannot exceed 248 bytes.|
167
168**Return value**
169
170| Type     | Description                            |
171| ------- | ------------------------------ |
172| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
173
174**Example**
175
176```js
177let ret : boolean = bluetooth.setLocalName('device_name');
178```
179
180
181## bluetooth.pairDevice<sup>(deprecated)</sup><a name="pairDevice"></a>
182
183pairDevice(deviceId: string): boolean
184
185Initiates Bluetooth pairing.
186
187> **NOTE**<br>
188> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.pairDevice](js-apis-bluetoothManager.md#bluetoothmanagerpairdevicedeprecated).
189
190**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
191
192**System capability**: SystemCapability.Communication.Bluetooth.Core
193
194**Parameters**
195
196| Name     | Type    | Mandatory  | Description                                 |
197| -------- | ------ | ---- | ----------------------------------- |
198| deviceId | string | Yes   | Address of the remote device to pair, for example, XX:XX:XX:XX:XX:XX.|
199
200**Return value**
201
202| Type     | Description                        |
203| ------- | -------------------------- |
204| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
205
206**Example**
207
208```js
209// The address can be scanned.
210let result : boolean = bluetooth.pairDevice("XX:XX:XX:XX:XX:XX");
211```
212
213
214## bluetooth.getProfileConnState<sup>8+</sup><sup>(deprecated)</sup><a name="getProfileConnState"></a>
215
216getProfileConnState(profileId: ProfileId): ProfileConnectionState
217
218Obtains the connection status of the specified profile.
219
220> **NOTE**<br>
221> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getProfileConnectionState](js-apis-bluetoothManager.md#bluetoothmanagergetprofileconnectionstatedeprecated).
222
223**Required permissions**: ohos.permission.USE_BLUETOOTH
224
225**System capability**: SystemCapability.Communication.Bluetooth.Core
226
227**Parameters**
228
229| Name      | Type       | Mandatory  | Description                                   |
230| --------- | --------- | ---- | ------------------------------------- |
231| ProfileId | profileId | Yes   | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
232
233**Return value**
234
235| Type                                             | Description               |
236| ------------------------------------------------- | ------------------- |
237| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
238
239**Example**
240
241```js
242let result : bluetooth.ProfileConnectionState = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
243```
244
245
246## bluetooth.cancelPairedDevice<sup>8+</sup><sup>(deprecated)</sup><a name="cancelPairedDevice"></a>
247
248cancelPairedDevice(deviceId: string): boolean
249
250Cancels a paired remote device.
251
252> **NOTE**<br>
253> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.cancelPairedDevice](js-apis-bluetoothManager.md#bluetoothmanagercancelpaireddevicedeprecated).
254
255**System API**: This is a system API.
256
257**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
258
259**System capability**: SystemCapability.Communication.Bluetooth.Core
260
261**Parameters**
262
263| Name     | Type    | Mandatory  | Description                                   |
264| -------- | ------ | ---- | ------------------------------------- |
265| deviceId | string | Yes   | Address of the remote device to cancel, for example, XX:XX:XX:XX:XX:XX.|
266
267**Return value**
268
269| Type     | Description                        |
270| ------- | -------------------------- |
271| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
272
273**Example**
274
275```js
276let result : boolean = bluetooth.cancelPairedDevice("XX:XX:XX:XX:XX:XX");
277```
278
279
280## bluetooth.getRemoteDeviceName<sup>8+</sup><sup>(deprecated)</sup><a name="getRemoteDeviceName"></a>
281
282getRemoteDeviceName(deviceId: string): string
283
284Obtains the name of the remote Bluetooth device.
285
286> **NOTE**<br>
287> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getRemoteDeviceName](js-apis-bluetoothManager.md#bluetoothmanagergetremotedevicenamedeprecated).
288
289**Required permissions**: ohos.permission.USE_BLUETOOTH
290
291**System capability**: SystemCapability.Communication.Bluetooth.Core
292
293**Parameters**
294
295| Name     | Type    | Mandatory  | Description                               |
296| -------- | ------ | ---- | --------------------------------- |
297| deviceId | string | Yes   | Address of the target remote device, for example, XX:XX:XX:XX:XX:XX.|
298
299**Return value**
300
301| Type    | Description           |
302| ------ | ------------- |
303| string | Device name (a string) obtained.|
304
305**Example**
306
307```js
308let remoteDeviceName : string = bluetooth.getRemoteDeviceName("XX:XX:XX:XX:XX:XX");
309```
310
311
312## bluetooth.getRemoteDeviceClass<sup>8+</sup><sup>(deprecated)</sup><a name="getRemoteDeviceClass"></a>
313
314getRemoteDeviceClass(deviceId: string): DeviceClass
315
316Obtains the class of the remote Bluetooth device.
317
318> **NOTE**<br>
319> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getRemoteDeviceClass](js-apis-bluetoothManager.md#bluetoothmanagergetremotedeviceclassdeprecated).
320
321**Required permissions**: ohos.permission.USE_BLUETOOTH
322
323**System capability**: SystemCapability.Communication.Bluetooth.Core
324
325**Parameters**
326
327| Name     | Type    | Mandatory  | Description                               |
328| -------- | ------ | ---- | --------------------------------- |
329| deviceId | string | Yes   | Address of the target remote device, for example, XX:XX:XX:XX:XX:XX.|
330
331**Return value**
332
333| Type                         | Description      |
334| --------------------------- | -------- |
335| [DeviceClass](#deviceclass) | Class of the remote device obtained.|
336
337**Example**
338
339```js
340let remoteDeviceClass : bluetooth.DeviceClass = bluetooth.getRemoteDeviceClass("XX:XX:XX:XX:XX:XX");
341```
342
343
344## bluetooth.getPairedDevices<sup>8+</sup><sup>(deprecated)</sup><a name="getPairedDevices"></a>
345
346getPairedDevices(): Array&lt;string&gt;
347
348Obtains the paired devices.
349
350> **NOTE**<br>
351> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getPairedDevices](js-apis-bluetoothManager.md#bluetoothmanagergetpaireddevicesdeprecated).
352
353**Required permissions**: ohos.permission.USE_BLUETOOTH
354
355**System capability**: SystemCapability.Communication.Bluetooth.Core
356
357**Return value**
358
359| Type                 | Description           |
360| ------------------- | ------------- |
361| Array&lt;string&gt; | Addresses of the paired Bluetooth devices.|
362
363**Example**
364
365```js
366let devices : Array<string> = bluetooth.getPairedDevices();
367```
368
369
370## bluetooth.setBluetoothScanMode<sup>8+</sup><sup>(deprecated)</sup><a name="setBluetoothScanMode"></a>
371
372setBluetoothScanMode(mode: ScanMode, duration: number): boolean
373
374Sets the Bluetooth scan mode so that the device can be discovered by a remote device.
375
376> **NOTE**<br>
377> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.setBluetoothScanMode](js-apis-bluetoothManager.md#bluetoothmanagersetbluetoothscanmodedeprecated).
378
379**Required permissions**: ohos.permission.USE_BLUETOOTH
380
381**System capability**: SystemCapability.Communication.Bluetooth.Core
382
383**Parameters**
384
385| Name     | Type                   | Mandatory  | Description                          |
386| -------- | --------------------- | ---- | ---------------------------- |
387| mode     | [ScanMode](#scanmode) | Yes   | Bluetooth scan mode to set.                     |
388| duration | number                | Yes   | Duration (in ms) in which the device can be discovered. The value **0** indicates unlimited time.|
389
390**Return value**
391
392| Type     | Description                        |
393| ------- | -------------------------- |
394| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
395
396**Example**
397
398```js
399// The device can be discovered and connected only when the discoverable and connectable mode is used.
400let result : boolean = bluetooth.setBluetoothScanMode(bluetooth.ScanMode
401    .SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100);
402```
403
404
405## bluetooth.getBluetoothScanMode<sup>8+</sup><sup>(deprecated)</sup><a name="getBluetoothScanMode"></a>
406
407getBluetoothScanMode(): ScanMode
408
409Obtains the Bluetooth scan mode.
410
411> **NOTE**<br>
412> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getBluetoothScanMode](js-apis-bluetoothManager.md#bluetoothmanagergetbluetoothscanmodedeprecated).
413
414**Required permissions**: ohos.permission.USE_BLUETOOTH
415
416**System capability**: SystemCapability.Communication.Bluetooth.Core
417
418**Return value**
419
420| Type                   | Description     |
421| --------------------- | ------- |
422| [ScanMode](#scanmode) | Bluetooth scan mode obtained.|
423
424**Example**
425
426```js
427let scanMode : bluetooth.ScanMode = bluetooth.getBluetoothScanMode();
428```
429
430
431## bluetooth.startBluetoothDiscovery<sup>8+</sup><sup>(deprecated)</sup><a name="startBluetoothDiscovery"></a>
432
433startBluetoothDiscovery(): boolean
434
435Starts Bluetooth scan to discover remote devices.
436
437> **NOTE**<br>
438> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.startBluetoothDiscovery](js-apis-bluetoothManager.md#bluetoothmanagerstartbluetoothdiscoverydeprecated).
439
440**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH and ohos.permission.LOCATION
441
442**System capability**: SystemCapability.Communication.Bluetooth.Core
443
444**Return value**
445
446| Type     | Description                        |
447| ------- | -------------------------- |
448| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
449
450**Example**
451
452```js
453let deviceId : Array<string>;
454function onReceiveEvent(data : Array<string>) {
455    deviceId = data;
456}
457bluetooth.on('bluetoothDeviceFind', onReceiveEvent);
458let result : boolean = bluetooth.startBluetoothDiscovery();
459```
460
461
462## bluetooth.stopBluetoothDiscovery<sup>8+</sup><sup>(deprecated)</sup><a name="stopBluetoothDiscovery"></a>
463
464stopBluetoothDiscovery(): boolean
465
466Stops Bluetooth scan.
467
468> **NOTE**<br>
469> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.stopBluetoothDiscovery](js-apis-bluetoothManager.md#bluetoothmanagerstopbluetoothdiscoverydeprecated).
470
471**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
472
473**System capability**: SystemCapability.Communication.Bluetooth.Core
474
475**Return value**
476
477| Type     | Description                        |
478| ------- | -------------------------- |
479| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
480
481**Example**
482
483```js
484let result : boolean = bluetooth.stopBluetoothDiscovery();
485```
486
487
488## bluetooth.setDevicePairingConfirmation<sup>8+</sup><sup>(deprecated)</sup><a name="setDevicePairingConfirmation"></a>
489
490setDevicePairingConfirmation(device: string, accept: boolean): boolean
491
492Sets the device pairing confirmation.
493
494> **NOTE**<br>
495> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.setDevicePairingConfirmation](js-apis-bluetoothManager.md#bluetoothmanagersetdevicepairingconfirmationdeprecated).
496
497**Required permissions**: ohos.permission.MANAGE_BLUETOOTH
498
499**System capability**: SystemCapability.Communication.Bluetooth.Core
500
501**Parameters**
502
503| Name   | Type     | Mandatory  | Description                              |
504| ------ | ------- | ---- | -------------------------------- |
505| device | string  | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
506| 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.       |
507
508**Return value**
509
510| Type     | Description                          |
511| ------- | ---------------------------- |
512| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
513
514**Example**
515
516```js
517// Subscribe to the pinRequired event and configure the pairing confirmation after receiving a pairing request from the remote device.
518function onReceivePinRequiredEvent(data : bluetooth.PinRequiredParam) { // data is the input parameter for the pairing request.
519    console.info('pin required  = '+ JSON.stringify(data));
520    bluetooth.setDevicePairingConfirmation(data.deviceId, true);
521}
522bluetooth.on("pinRequired", onReceivePinRequiredEvent);
523```
524
525
526## bluetooth.on('bluetoothDeviceFind')<sup>8+</sup><sup>(deprecated)</sup><a name="bluetoothDeviceFind"></a>
527
528on(type: "bluetoothDeviceFind", callback: Callback&lt;Array&lt;string&gt;&gt;): void
529
530Subscribes to the Bluetooth device discovery events.
531
532> **NOTE**<br>
533> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('bluetoothDeviceFind')](js-apis-bluetoothManager.md#bluetoothmanageronbluetoothdevicefinddeprecated).
534
535**Required permissions**: ohos.permission.USE_BLUETOOTH
536
537**System capability**: SystemCapability.Communication.Bluetooth.Core
538
539**Parameters**
540
541| Name     | Type                                 | Mandatory  | Description                                    |
542| -------- | ----------------------------------- | ---- | -------------------------------------- |
543| type     | string                              | Yes   | Event type. The value **bluetoothDeviceFind** indicates an event reported when a Bluetooth device is discovered.|
544| callback | Callback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the discovered devices. You need to implement this callback.   |
545
546**Return value**
547
548No value is returned.
549
550**Example**
551
552```js
553function onReceiveEvent(data : Array<string>) { // data is an array of Bluetooth device addresses.
554    console.info('bluetooth device find = '+ JSON.stringify(data));
555}
556bluetooth.on('bluetoothDeviceFind', onReceiveEvent);
557```
558
559
560## bluetooth.off('bluetoothDeviceFind')<sup>8+</sup><sup>(deprecated)</sup>
561
562off(type: "bluetoothDeviceFind", callback?: Callback&lt;Array&lt;string&gt;&gt;): void
563
564Unsubscribes from the Bluetooth device discovery events.
565
566> **NOTE**<br>
567> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('bluetoothDeviceFind')](js-apis-bluetoothManager.md#bluetoothmanageroffbluetoothdevicefinddeprecated).
568
569**Required permissions**: ohos.permission.USE_BLUETOOTH
570
571**System capability**: SystemCapability.Communication.Bluetooth.Core
572
573**Parameters**
574
575| Name     | Type                                 | Mandatory  | Description                                      |
576| -------- | ----------------------------------- | ---- | ---------------------------------------- |
577| type     | string                              | Yes   | Event type. The value **bluetoothDeviceFind** indicates an event reported when a Bluetooth device is discovered.  |
578| 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**.|
579
580**Return value**
581
582No value is returned.
583
584**Example**
585
586```js
587function onReceiveEvent(data : Array<string>) {
588    console.info('bluetooth device find = '+ JSON.stringify(data));
589}
590bluetooth.on('bluetoothDeviceFind', onReceiveEvent);
591bluetooth.off('bluetoothDeviceFind', onReceiveEvent);
592```
593
594
595## bluetooth.on('pinRequired')<sup>8+</sup><sup>(deprecated)</sup>
596
597on(type: "pinRequired", callback: Callback&lt;PinRequiredParam&gt;): void
598
599Subscribes to the pairing request events of the remote Bluetooth device.
600
601> **NOTE**<br>
602> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('pinRequired')](js-apis-bluetoothManager.md#bluetoothmanageronpinrequireddeprecated).
603
604**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
605
606**System capability**: SystemCapability.Communication.Bluetooth.Core
607
608**Parameters**
609
610| Name     | Type                                      | Mandatory  | Description                              |
611| -------- | ---------------------------------------- | ---- | -------------------------------- |
612| type     | string                                   | Yes   | Event type. The value **pinRequired** indicates a pairing request event.    |
613| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | Yes   | Callback invoked to return the pairing request. You need to implement this callback.|
614
615**Return value**
616
617No value is returned.
618
619**Example**
620
621```js
622function onReceiveEvent(data : bluetooth.PinRequiredParam) { // data is the pairing request parameter.
623    console.info('pin required = '+ JSON.stringify(data));
624}
625bluetooth.on('pinRequired', onReceiveEvent);
626```
627
628
629## bluetooth.off('pinRequired')<sup>8+</sup><sup>(deprecated)</sup>
630
631off(type: "pinRequired", callback?: Callback&lt;PinRequiredParam&gt;): void
632
633Unsubscribes from the pairing request events of the remote Bluetooth device.
634
635> **NOTE**<br>
636> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('pinRequired')](js-apis-bluetoothManager.md#bluetoothmanageroffpinrequireddeprecated).
637
638**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
639
640**System capability**: SystemCapability.Communication.Bluetooth.Core
641
642**Parameters**
643
644| Name     | Type                                      | Mandatory  | Description                                      |
645| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
646| type     | string                                   | Yes   | Event type. The value **pinRequired** indicates a pairing request event.            |
647| 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**.|
648
649**Return value**
650
651No value is returned.
652
653**Example**
654
655```js
656function onReceiveEvent(data : bluetooth.PinRequiredParam) {
657    console.info('pin required = '+ JSON.stringify(data));
658}
659bluetooth.on('pinRequired', onReceiveEvent);
660bluetooth.off('pinRequired', onReceiveEvent);
661```
662
663
664## bluetooth.on('bondStateChange')<sup>8+</sup><sup>(deprecated)</sup>
665
666on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void
667
668Subscribes to the Bluetooth pairing state changes.
669
670> **NOTE**<br>
671> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('bondStateChange')](js-apis-bluetoothManager.md#bluetoothmanageronbondstatechangedeprecated).
672
673**Required permissions**: ohos.permission.USE_BLUETOOTH
674
675**System capability**: SystemCapability.Communication.Bluetooth.Core
676
677**Parameters**
678
679| Name     | Type                                      | Mandatory  | Description                                  |
680| -------- | ---------------------------------------- | ---- | ------------------------------------ |
681| type     | string                                   | Yes   | Event type. The value **bondStateChange** indicates a Bluetooth pairing state change event.|
682| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | Yes   | Callback invoked to return the pairing state. You need to implement this callback.   |
683
684**Return value**
685
686No value is returned.
687
688**Example**
689
690```js
691function onReceiveEvent(data : bluetooth.BondStateParam) { // data, as the input parameter of the callback, indicates the pairing state.
692    console.info('pair state = '+ JSON.stringify(data));
693}
694bluetooth.on('bondStateChange', onReceiveEvent);
695```
696
697
698## bluetooth.off('bondStateChange')<sup>8+</sup><sup>(deprecated)</sup>
699
700off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void
701
702Unsubscribes from the Bluetooth pairing state changes.
703
704> **NOTE**<br>
705> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('bondStateChange')](js-apis-bluetoothManager.md#bluetoothmanageroffbondstatechangedeprecated).
706
707**Required permissions**: ohos.permission.USE_BLUETOOTH
708
709**System capability**: SystemCapability.Communication.Bluetooth.Core
710
711**Parameters**
712
713| Name     | Type                                      | Mandatory  | Description                                      |
714| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
715| type     | string                                   | Yes   | Event type. The value **bondStateChange** indicates a Bluetooth pairing state change event.    |
716| 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**.|
717
718**Return value**
719
720No value is returned.
721
722**Example**
723
724```js
725function onReceiveEvent(data : bluetooth.BondStateParam) {
726    console.info('bond state = '+ JSON.stringify(data));
727}
728bluetooth.on('bondStateChange', onReceiveEvent);
729bluetooth.off('bondStateChange', onReceiveEvent);
730```
731
732
733## bluetooth.on('stateChange')<sup>8+</sup><sup>(deprecated)</sup>
734
735on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void
736
737Subscribes to the Bluetooth connection state changes.
738
739> **NOTE**<br>
740> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('stateChange')](js-apis-bluetoothManager.md#bluetoothmanageronstatechangedeprecated).
741
742**Required permissions**: ohos.permission.USE_BLUETOOTH
743
744**System capability**: SystemCapability.Communication.Bluetooth.Core
745
746**Parameters**
747
748| Name     | Type                                      | Mandatory  | Description                              |
749| -------- | ---------------------------------------- | ---- | -------------------------------- |
750| type     | string                                   | Yes   | Event type. The value **stateChange** indicates a Bluetooth connection state change event.  |
751| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | Yes   | Callback invoked to return the Bluetooth connection state. You need to implement this callback.|
752
753**Return value**
754
755No value is returned.
756
757**Example**
758
759```js
760function onReceiveEvent(data : bluetooth.BluetoothState) {
761    console.info('bluetooth state = '+ JSON.stringify(data));
762}
763bluetooth.on('stateChange', onReceiveEvent);
764```
765
766
767## bluetooth.off('stateChange')<sup>8+</sup><sup>(deprecated)</sup>
768
769off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void
770
771Unsubscribes from the Bluetooth connection state changes.
772
773> **NOTE**<br>
774> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('stateChange')](js-apis-bluetoothManager.md#bluetoothmanageroffstatechangedeprecated).
775
776**Required permissions**: ohos.permission.USE_BLUETOOTH
777
778**System capability**: SystemCapability.Communication.Bluetooth.Core
779
780**Parameters**
781
782| Name     | Type                                      | Mandatory  | Description                                      |
783| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
784| type     | string                                   | Yes   | Event type. The value **stateChange** indicates a Bluetooth connection state change event.          |
785| 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**.|
786
787**Return value**
788
789No value is returned.
790
791**Example**
792
793```js
794function onReceiveEvent(data : bluetooth.BluetoothState) {
795    console.info('bluetooth state = '+ JSON.stringify(data));
796}
797bluetooth.on('stateChange', onReceiveEvent);
798bluetooth.off('stateChange', onReceiveEvent);
799```
800
801
802## bluetooth.sppListen<sup>8+</sup><sup>(deprecated)</sup><a name="sppListen"></a>
803
804sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
805
806Creates a server listening socket.
807
808> **NOTE**<br>
809> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppListen](js-apis-bluetoothManager.md#bluetoothmanagerspplistendeprecated).
810
811**Required permissions**: ohos.permission.USE_BLUETOOTH
812
813**System capability**: SystemCapability.Communication.Bluetooth.Core
814
815**Parameters**
816
817| Name     | Type                         | Mandatory  | Description                     |
818| -------- | --------------------------- | ---- | ----------------------- |
819| name     | string                      | Yes   | Name of the service.                 |
820| option   | [SppOption](#sppoption)     | Yes   | Serial port profile (SPP) listening configuration.             |
821| callback | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the server socket ID.|
822
823**Example**
824
825```js
826import { BusinessError } from '@ohos.base';
827let serverNumber = -1;
828function serverSocket(code : BusinessError, number : number) {
829  console.log('bluetooth error code: ' + code.code);
830  if (code.code == 0) {
831    console.log('bluetooth serverSocket Number: ' + number);
832    serverNumber = number;
833  }
834}
835
836let sppOption : bluetooth.SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
837bluetooth.sppListen('server1', sppOption, serverSocket);
838```
839
840
841## bluetooth.sppAccept<sup>8+</sup><sup>(deprecated)</sup><a name="sppAccept"></a>
842
843sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void
844
845Listens for a connection to be made to this socket from the client and accepts it.
846
847> **NOTE**<br>
848> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppAccept](js-apis-bluetoothManager.md#bluetoothmanagersppacceptdeprecated).
849
850**System capability**: SystemCapability.Communication.Bluetooth.Core
851
852**Parameters**
853
854| Name         | Type                         | Mandatory  | Description                     |
855| ------------ | --------------------------- | ---- | ----------------------- |
856| serverSocket | number                      | Yes   | Server socket ID.          |
857| callback     | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the client socket ID.|
858
859**Example**
860
861```js
862import { BusinessError } from '@ohos.base';
863let serverNumber = -1;
864function serverSocket(code : BusinessError, number : number) {
865  console.log('bluetooth error code: ' + code.code);
866  if (code.code == 0) {
867    console.log('bluetooth serverSocket Number: ' + number);
868    serverNumber = number;
869  }
870}
871let clientNumber = -1;
872function acceptClientSocket(code : BusinessError, number : number) {
873  console.log('bluetooth error code: ' + code.code);
874  if (code.code == 0) {
875    console.log('bluetooth clientSocket Number: ' + number);
876    // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the server.
877    clientNumber = number;
878  }
879}
880bluetooth.sppAccept(serverNumber, acceptClientSocket);
881```
882
883
884## bluetooth.sppConnect<sup>8+</sup><sup>(deprecated)</sup><a name="sppConnect"></a>
885
886sppConnect(device: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
887
888Initiates an SPP connection to a remote device from the client.
889
890> **NOTE**<br>
891> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppConnect](js-apis-bluetoothManager.md#bluetoothmanagersppconnectdeprecated).
892
893**Required permissions**: ohos.permission.USE_BLUETOOTH
894
895**System capability**: SystemCapability.Communication.Bluetooth.Core
896
897**Parameters**
898
899| Name     | Type                         | Mandatory  | Description                            |
900| -------- | --------------------------- | ---- | ------------------------------ |
901| device   | string                      | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
902| option   | [SppOption](#sppoption)     | Yes   | Configuration for connecting to the SPP client.                 |
903| callback | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the client socket ID.       |
904
905**Example**
906
907```js
908import { BusinessError } from '@ohos.base';
909let clientNumber = -1;
910function clientSocket(code : BusinessError, number : number) {
911  if (code.code != 0 || code == null) {
912    return;
913  }
914  console.log('bluetooth serverSocket Number: ' + number);
915  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
916  clientNumber = number;
917}
918let sppOption : bluetooth.SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
919bluetooth.sppConnect('XX:XX:XX:XX:XX:XX', sppOption, clientSocket);
920```
921
922
923## bluetooth.sppCloseServerSocket<sup>8+</sup><sup>(deprecated)</sup><a name="sppCloseServerSocket"></a>
924
925sppCloseServerSocket(socket: number): void
926
927Closes the listening socket of the server.
928
929> **NOTE**<br>
930> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppCloseServerSocket](js-apis-bluetoothManager.md#bluetoothmanagersppcloseserversocketdeprecated).
931
932**System capability**: SystemCapability.Communication.Bluetooth.Core
933
934**Parameters**
935
936| Name   | Type    | Mandatory  | Description             |
937| ------ | ------ | ---- | --------------- |
938| socket | number | Yes   | ID of the listening socket on the server. The ID is obtained by **sppListen**.|
939
940**Example**
941
942```js
943import { BusinessError } from '@ohos.base';
944let serverNumber = -1;
945function serverSocket(code : BusinessError, number : number) {
946  console.log('bluetooth error code: ' + code.code);
947  if (code.code == 0) {
948    console.log('bluetooth serverSocket Number: ' + number);
949    serverNumber = number;
950  }
951}
952bluetooth.sppCloseServerSocket(serverNumber);
953```
954
955
956## bluetooth.sppCloseClientSocket<sup>8+</sup><sup>(deprecated)</sup><a name="sppCloseClientSocket"></a>
957
958sppCloseClientSocket(socket: number): void
959
960Closes the client socket.
961
962> **NOTE**<br>
963> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppCloseClientSocket](js-apis-bluetoothManager.md#bluetoothmanagersppcloseclientsocketdeprecated).
964
965**System capability**: SystemCapability.Communication.Bluetooth.Core
966
967**Parameters**
968
969| Name   | Type    | Mandatory  | Description           |
970| ------ | ------ | ---- | ------------- |
971| Name   | Type    | Mandatory  | Description           |
972| socket | number | Yes   | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.|
973
974**Example**
975
976```js
977import { BusinessError } from '@ohos.base';
978let clientNumber = -1;
979function clientSocket(code : BusinessError, number : number) {
980  if (code.code != 0 || code == null) {
981    return;
982  }
983  console.log('bluetooth serverSocket Number: ' + number);
984  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
985  clientNumber = number;
986}
987bluetooth.sppCloseClientSocket(clientNumber);
988```
989
990
991## bluetooth.sppWrite<sup>8+</sup><sup>(deprecated)</sup><a name="sppWrite"></a>
992
993sppWrite(clientSocket: number, data: ArrayBuffer): boolean
994
995Writes data to the remote device through the socket.
996
997> **NOTE**<br>
998> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppWrite](js-apis-bluetoothManager.md#bluetoothmanagersppwritedeprecated).
999
1000**System capability**: SystemCapability.Communication.Bluetooth.Core
1001
1002**Parameters**
1003
1004| Name         | Type         | Mandatory  | Description           |
1005| ------------ | ----------- | ---- | ------------- |
1006| clientSocket | number      | Yes   | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.|
1007| data         | ArrayBuffer | Yes   | Data to write.       |
1008
1009**Return value**
1010
1011| Type     | Description                       |
1012| ------- | ------------------------- |
1013| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1014
1015**Example**
1016
1017```js
1018import { BusinessError } from '@ohos.base';
1019let clientNumber = -1;
1020function clientSocket(code : BusinessError, number : number) {
1021  if (code.code != 0 || code == null) {
1022    return;
1023  }
1024  console.log('bluetooth serverSocket Number: ' + number);
1025  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
1026  clientNumber = number;
1027}
1028let arrayBuffer = new ArrayBuffer(8);
1029let data = new Uint8Array(arrayBuffer);
1030data[0] = 123;
1031let ret : boolean = bluetooth.sppWrite(clientNumber, arrayBuffer);
1032if (ret) {
1033  console.log('spp write successfully');
1034} else {
1035  console.log('spp write failed');
1036}
1037```
1038
1039
1040## bluetooth.on('sppRead')<sup>8+</sup><sup>(deprecated)</sup>
1041
1042on(type: "sppRead", clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void
1043
1044> **NOTE**<br>
1045> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('sppRead')](js-apis-bluetoothManager.md#bluetoothmanageronsppreaddeprecated).
1046
1047Subscribes to the SPP read request events.
1048
1049**System capability**: SystemCapability.Communication.Bluetooth.Core
1050
1051**Parameters**
1052
1053| Name         | Type                         | Mandatory  | Description                        |
1054| ------------ | --------------------------- | ---- | -------------------------- |
1055| type         | string                      | Yes   | Event type. The value **sppRead** indicates an SPP read request event.|
1056| clientSocket | number                      | Yes   | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.             |
1057| callback     | Callback&lt;ArrayBuffer&gt; | Yes   | Callback invoked to return the data read.         |
1058
1059**Return value**
1060
1061No value is returned.
1062
1063**Example**
1064
1065```js
1066import { BusinessError } from '@ohos.base';
1067let clientNumber = -1;
1068function clientSocket(code : BusinessError, number : number) {
1069  if (code.code != 0 || code == null) {
1070    return;
1071  }
1072  console.log('bluetooth serverSocket Number: ' + number);
1073  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
1074  clientNumber = number;
1075}
1076function dataRead(dataBuffer : ArrayBuffer) {
1077  let data = new Uint8Array(dataBuffer);
1078  console.log('bluetooth data is: ' + data[0]);
1079}
1080bluetooth.on('sppRead', clientNumber, dataRead);
1081```
1082
1083
1084## bluetooth.off('sppRead')<sup>8+</sup><sup>(deprecated)</sup>
1085
1086off(type: "sppRead", clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void
1087
1088Unsubscribes from the SPP read request events.
1089
1090> **NOTE**<br>
1091> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('sppRead')](js-apis-bluetoothManager.md#bluetoothmanageroffsppreaddeprecated).
1092
1093**System capability**: SystemCapability.Communication.Bluetooth.Core
1094
1095**Parameters**
1096
1097| Name         | Type                         | Mandatory  | Description                                      |
1098| ------------ | --------------------------- | ---- | ---------------------------------------- |
1099| type         | string                      | Yes   | Event type. The value **sppRead** indicates an SPP read request event.              |
1100| clientSocket | number                      | Yes   | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.                           |
1101| 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**.|
1102
1103**Return value**
1104
1105No value is returned.
1106
1107**Example**
1108
1109```js
1110import { BusinessError } from '@ohos.base';
1111let clientNumber = -1;
1112function clientSocket(code : BusinessError, number : number) {
1113  if (code.code != 0 || code == null) {
1114    return;
1115  }
1116  console.log('bluetooth serverSocket Number: ' + number);
1117  // The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
1118  clientNumber = number;
1119}
1120bluetooth.off('sppRead', clientNumber);
1121```
1122
1123
1124## bluetooth.getProfile<sup>8+</sup><sup>(deprecated)</sup><a name="bt-getProfile"></a>
1125
1126getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile
1127
1128Obtains a profile object.
1129
1130> **NOTE**<br>
1131> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getProfileInstance](js-apis-bluetoothManager.md#bluetoothmanagergetprofileinstancedeprecated).
1132
1133**System capability**: SystemCapability.Communication.Bluetooth.Core
1134
1135**Parameters**
1136
1137| Name      | Type       | Mandatory  | Description                                   |
1138| --------- | --------- | ---- | ------------------------------------- |
1139| profileId | [ProfileId](#ProfileId) | Yes   | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
1140
1141**Return value**
1142
1143| Type                                                        | Description                                                        |
1144| ------------------------------------------------------------ | ------------------------------------------------------------ |
1145| [A2dpSourceProfile](#a2dpsourceprofile) or [HandsFreeAudioGatewayProfile](#handsfreeaudiogatewayprofile)| Profile object obtained. Only **A2dpSourceProfile** and **HandsFreeAudioGatewayProfile** are supported.|
1146
1147**Example**
1148
1149```js
1150let a2dpSrc : bluetooth.A2dpSourceProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
1151```
1152
1153
1154## bluetooth.BLE
1155
1156### createGattServer<sup>(deprecated)</sup>
1157
1158createGattServer(): GattServer
1159
1160Creates a **GattServer** instance.
1161
1162> **NOTE**<br>
1163> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.createGattServer](js-apis-bluetoothManager.md#creategattserverdeprecated).
1164
1165**System capability**: SystemCapability.Communication.Bluetooth.Core
1166
1167**Return value**
1168
1169| Type                       | Description                                  |
1170| ------------------------- | ------------------------------------ |
1171| [GattServer](#gattserver) | **GattServer** instance created. Before using a method of the server, you must create a **GattSever** instance.|
1172
1173**Example**
1174
1175```js
1176let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
1177```
1178
1179
1180### createGattClientDevice<sup>(deprecated)</sup>
1181
1182createGattClientDevice(deviceId: string): GattClientDevice
1183
1184Creates a **GattClientDevice** instance.
1185
1186> **NOTE**<br>
1187> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.createGattClientDevice](js-apis-bluetoothManager.md#creategattclientdevicedeprecated).
1188
1189**System capability**: SystemCapability.Communication.Bluetooth.Core
1190
1191**Parameters**
1192
1193| Name     | Type    | Mandatory  | Description                                  |
1194| -------- | ------ | ---- | ------------------------------------ |
1195| deviceId | string | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
1196
1197**Return value**
1198
1199| Type                                   | Description                                  |
1200| ------------------------------------- | ------------------------------------ |
1201| [GattClientDevice](#gattclientdevice) | **GattClientDevice** instance created. Before using a method of the client, you must create a **GattClientDevice** instance.|
1202
1203**Example**
1204
1205```js
1206let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
1207```
1208
1209
1210### getConnectedBLEDevices<sup>(deprecated)</sup>
1211
1212getConnectedBLEDevices(): Array&lt;string&gt;
1213
1214Obtains the BLE devices connected to this device.
1215
1216> **NOTE**<br>
1217> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.getConnectedBLEDevices](js-apis-bluetoothManager.md#getconnectedbledevicesdeprecated).
1218
1219**Required permissions**: ohos.permission.USE_BLUETOOTH
1220
1221**System capability**: SystemCapability.Communication.Bluetooth.Core
1222
1223**Return value**
1224
1225| Type                 | Description                 |
1226| ------------------- | ------------------- |
1227| Array&lt;string&gt; | Addresses of the BLE devices connected to this device.|
1228
1229**Example**
1230
1231```js
1232let result : Array<string> = bluetooth.BLE.getConnectedBLEDevices();
1233```
1234
1235
1236### startBLEScan<sup>(deprecated)</sup>
1237
1238startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
1239
1240Starts a BLE scan.
1241
1242> **NOTE**<br>
1243> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.startBLEScan](js-apis-bluetoothManager.md#startblescandeprecated).
1244
1245**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH, ohos.permission.MANAGE_BLUETOOTH, and ohos.permission.LOCATION
1246
1247**System capability**: SystemCapability.Communication.Bluetooth.Core
1248
1249**Parameters**
1250
1251| Name    | Type                                    | Mandatory  | Description                                 |
1252| ------- | -------------------------------------- | ---- | ----------------------------------- |
1253| 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.|
1254| options | [ScanOptions](#scanoptions)            | No   | Scan options.                    |
1255
1256**Return value**
1257
1258No value is returned.
1259
1260**Example**
1261
1262```js
1263function onReceiveEvent(data : Array<bluetooth.ScanResult>) {
1264    console.info('BLE scan device find result = '+ JSON.stringify(data));
1265}
1266bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent);
1267let scanOptions : bluetooth.ScanOptions = {
1268    interval: 500,
1269    dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER,
1270    matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE,
1271}
1272
1273let scanFilter : bluetooth.ScanFilter = {
1274    deviceId:"XX:XX:XX:XX:XX:XX",
1275    name:"test",
1276    serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
1277}
1278bluetooth.BLE.startBLEScan(
1279    [scanFilter], scanOptions
1280);
1281```
1282
1283
1284### stopBLEScan<sup>(deprecated)</sup>
1285
1286stopBLEScan(): void
1287
1288Stops the BLE scan.
1289
1290> **NOTE**<br>
1291> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.stopBLEScan](js-apis-bluetoothManager.md#stopblescandeprecated).
1292
1293**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1294
1295**System capability**: SystemCapability.Communication.Bluetooth.Core
1296
1297**Return value**
1298
1299No value is returned.
1300
1301**Example**
1302
1303```js
1304bluetooth.BLE.stopBLEScan();
1305```
1306
1307
1308### on('BLEDeviceFind')<sup>(deprecated)</sup>
1309
1310on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
1311
1312Subscribe to the BLE device discovery events.
1313
1314> **NOTE**<br>
1315> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.on('BLEDeviceFind')](js-apis-bluetoothManager.md#onbledevicefinddeprecated).
1316
1317**Required permissions**: ohos.permission.USE_BLUETOOTH
1318
1319**System capability**: SystemCapability.Communication.Bluetooth.Core
1320
1321**Parameters**
1322
1323| Name     | Type                                      | Mandatory  | Description                                 |
1324| -------- | ---------------------------------------- | ---- | ----------------------------------- |
1325| type     | string                                   | Yes   | Event type. The value **BLEDeviceFind** indicates an event reported when a BLE device is discovered.  |
1326| callback | Callback&lt;Array&lt;[ScanResult](#scanresult)&gt;&gt; | Yes   | Callback invoked to return the discovered devices. You need to implement this callback.|
1327
1328**Return value**
1329
1330No value is returned.
1331
1332**Example**
1333
1334```js
1335function onReceiveEvent(data : Array<bluetooth.ScanResult>) {
1336    console.info('bluetooth device find = '+ JSON.stringify(data));
1337}
1338bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent);
1339```
1340
1341
1342### off('BLEDeviceFind')<sup>(deprecated)</sup>
1343
1344off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
1345
1346Unsubscribes from the BLE device discovery events.
1347
1348> **NOTE**<br>
1349> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.off('BLEDeviceFind')](js-apis-bluetoothManager.md#offbledevicefinddeprecated).
1350
1351**Required permissions**: ohos.permission.USE_BLUETOOTH
1352
1353**System capability**: SystemCapability.Communication.Bluetooth.Core
1354
1355**Parameters**
1356
1357| Name     | Type                                      | Mandatory  | Description                                      |
1358| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1359| type     | string                                   | Yes   | Event type. The value **BLEDeviceFind** indicates an event reported when a BLE device is discovered.       |
1360| 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**.|
1361
1362**Return value**
1363
1364No value is returned.
1365
1366**Example**
1367
1368```js
1369function onReceiveEvent(data : Array<bluetooth.ScanResult>) {
1370    console.info('bluetooth device find = '+ JSON.stringify(data));
1371}
1372bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent);
1373bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
1374```
1375
1376
1377## BaseProfile
1378
1379Provides the profile base class.
1380
1381
1382### getConnectionDevices<sup>8+</sup><sup>(deprecated)</sup><a name="getConnectionDevices"></a>
1383
1384getConnectionDevices(): Array&lt;string&gt;
1385
1386Obtains the connected devices.
1387
1388> **NOTE**<br>
1389> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.BaseProfile.getConnectionDevices](js-apis-bluetoothManager.md#getconnectiondevicesdeprecated).
1390
1391**Required permissions**: ohos.permission.USE_BLUETOOTH
1392
1393**System capability**: SystemCapability.Communication.Bluetooth.Core
1394
1395**Return value**
1396
1397| Type                 | Description           |
1398| ------------------- | ------------- |
1399| Array&lt;string&gt; | Addresses of the connected devices.|
1400
1401**Example**
1402
1403```js
1404let a2dpSrc : bluetooth.A2dpSourceProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
1405let retArray : Array<string> = a2dpSrc.getConnectionDevices();
1406```
1407
1408### getDeviceState<sup>8+</sup><sup>(deprecated)</sup><a name="getDeviceState"></a>
1409
1410getDeviceState(device: string): ProfileConnectionState
1411
1412Obtains the connection state of the profile.
1413
1414> **NOTE**<br>
1415> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.BaseProfile.getDeviceState](js-apis-bluetoothManager.md#getdevicestatedeprecated).
1416
1417**Required permissions**: ohos.permission.USE_BLUETOOTH
1418
1419**System capability**: SystemCapability.Communication.Bluetooth.Core
1420
1421**Parameters**
1422
1423| Name   | Type    | Mandatory  | Description     |
1424| ------ | ------ | ---- | ------- |
1425| device | string | Yes   | Address of the target device.|
1426
1427**Return value**
1428
1429| Type                                             | Description                   |
1430| ------------------------------------------------- | ----------------------- |
1431| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
1432
1433**Example**
1434
1435```js
1436let a2dpSrc : bluetooth.A2dpSourceProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
1437let ret : bluetooth.ProfileConnectionState = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX');
1438```
1439
1440## A2dpSourceProfile
1441
1442Before using a method of **A2dpSourceProfile**, you need to create an instance of this class by using the **getProfile()** method.
1443
1444
1445### connect<sup>8+</sup><sup>(deprecated)</sup><a name="a2dp-connect"></a>
1446
1447connect(device: string): boolean
1448
1449Sets up an Advanced Audio Distribution Profile (A2DP) connection.
1450
1451> **NOTE**<br>
1452> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.connect](js-apis-bluetoothManager.md#connectdeprecated).
1453
1454**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1455
1456**System capability**: SystemCapability.Communication.Bluetooth.Core
1457
1458**Parameters**
1459
1460| Name   | Type    | Mandatory  | Description     |
1461| ------ | ------ | ---- | ------- |
1462| device | string | Yes   | Address of the target device.|
1463
1464**Return value**
1465
1466| Type     | Description                 |
1467| ------- | ------------------- |
1468| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1469
1470**Example**
1471
1472```js
1473let a2dpSrc : bluetooth.A2dpSourceProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
1474let ret : boolean = a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
1475```
1476
1477
1478### disconnect<sup>8+</sup><sup>(deprecated)</sup><a name="a2dp-disconnect"></a>
1479
1480disconnect(device: string): boolean
1481
1482Disconnects an A2DP connection.
1483
1484> **NOTE**<br>
1485> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.disconnect](js-apis-bluetoothManager.md#disconnectdeprecated).
1486
1487**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1488
1489**System capability**: SystemCapability.Communication.Bluetooth.Core
1490
1491**Parameters**
1492
1493| Name   | Type    | Mandatory  | Description     |
1494| ------ | ------ | ---- | ------- |
1495| device | string | Yes   | Address of the target device.|
1496
1497**Return value**
1498
1499| Type     | Description                 |
1500| ------- | ------------------- |
1501| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1502
1503**Example**
1504
1505```js
1506let a2dpSrc : bluetooth.A2dpSourceProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
1507let ret : boolean = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
1508```
1509
1510
1511### on('connectionStateChange')<sup>8+</sup><sup>(deprecated)</sup>
1512
1513on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
1514
1515Subscribes to the A2DP connection state changes.
1516
1517> **NOTE**<br>
1518> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.on('connectionStateChange')](js-apis-bluetoothManager.md#onconnectionstatechangedeprecated).
1519
1520**System capability**: SystemCapability.Communication.Bluetooth.Core
1521
1522**Parameters**
1523
1524| Name     | Type                                      | Mandatory  | Description                                      |
1525| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1526| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates an A2DP connection state change event.|
1527| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes   | Callback invoked to return the A2DP connection state change event.                              |
1528
1529**Return value**
1530
1531No value is returned.
1532
1533**Example**
1534
1535```js
1536function onReceiveEvent(data : bluetooth.StateChangeParam) {
1537    console.info('a2dp state = '+ JSON.stringify(data));
1538}
1539let a2dpSrc : bluetooth.A2dpSourceProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
1540a2dpSrc.on('connectionStateChange', onReceiveEvent);
1541```
1542
1543
1544### off('connectionStateChange')<sup>8+</sup><sup>(deprecated)</sup>
1545
1546off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
1547
1548Unsubscribes from the A2DP connection state changes.
1549
1550> **NOTE**<br>
1551> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.off('connectionStateChange')](js-apis-bluetoothManager.md#offconnectionstatechangedeprecated).
1552
1553**System capability**: SystemCapability.Communication.Bluetooth.Core
1554
1555**Parameters**
1556
1557| Name     | Type                                      | Mandatory  | Description                                      |
1558| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1559| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates an A2DP connection state change event.|
1560| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No   | Callback for the A2DP connection state change event.                              |
1561
1562**Return value**
1563
1564No value is returned.
1565
1566**Example**
1567
1568```js
1569function onReceiveEvent(data : bluetooth.StateChangeParam) {
1570    console.info('a2dp state = '+ JSON.stringify(data));
1571}
1572let a2dpSrc : bluetooth.A2dpSourceProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
1573a2dpSrc.on('connectionStateChange', onReceiveEvent);
1574a2dpSrc.off('connectionStateChange', onReceiveEvent);
1575```
1576
1577
1578### getPlayingState<sup>8+</sup><sup>(deprecated)</sup>
1579
1580getPlayingState(device: string): PlayingState
1581
1582Obtains the playing state of a device.
1583
1584> **NOTE**<br>
1585> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.getPlayingState](js-apis-bluetoothManager.md#getplayingstatedeprecated).
1586
1587**System capability**: SystemCapability.Communication.Bluetooth.Core
1588
1589**Parameters**
1590
1591| Name   | Type    | Mandatory  | Description     |
1592| ------ | ------ | ---- | ------- |
1593| device | string | Yes   | Address of the target device.|
1594
1595**Return value**
1596
1597| Type                           | Description        |
1598| ----------------------------- | ---------- |
1599| [PlayingState](#PlayingState) | Playing state of the remote device obtained.|
1600
1601**Example**
1602
1603```js
1604let a2dpSrc : bluetooth.A2dpSourceProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
1605let state : bluetooth.PlayingState = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
1606```
1607
1608
1609## HandsFreeAudioGatewayProfile
1610
1611Before using a method of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using the **getProfile()** method.
1612
1613
1614### connect<sup>8+</sup><sup>(deprecated)</sup><a name="hfp-connect"></a>
1615
1616connect(device: string): boolean
1617
1618Sets up a Hands-free Profile (HFP) connection of a device.
1619
1620> **NOTE**<br>
1621> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.connect](js-apis-bluetoothManager.md#connect).
1622
1623**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1624
1625**System capability**: SystemCapability.Communication.Bluetooth.Core
1626
1627**Parameters**
1628
1629| Name   | Type    | Mandatory  | Description     |
1630| ------ | ------ | ---- | ------- |
1631| device | string | Yes   | Address of the target device.|
1632
1633**Return value**
1634
1635| Type     | Description                 |
1636| ------- | ------------------- |
1637| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1638
1639**Example**
1640
1641```js
1642let hfpAg : bluetooth.HandsFreeAudioGatewayProfile= bluetooth.getProfile(bluetooth.ProfileId
1643    .PROFILE_HANDS_FREE_AUDIO_GATEWAY);
1644let ret : boolean = hfpAg.connect('XX:XX:XX:XX:XX:XX');
1645```
1646
1647
1648### disconnect<sup>8+</sup><sup>(deprecated)</sup><a name="hfp-disconnect"></a>
1649
1650disconnect(device: string): boolean
1651
1652Disconnects the HFP connection of a device.
1653
1654> **NOTE**<br>
1655> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.disconnect](js-apis-bluetoothManager.md#disconnectdeprecated-1).
1656
1657**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1658
1659**System capability**: SystemCapability.Communication.Bluetooth.Core
1660
1661**Parameters**
1662
1663| Name   | Type    | Mandatory  | Description     |
1664| ------ | ------ | ---- | ------- |
1665| device | string | Yes   | Address of the target device.|
1666
1667**Return value**
1668
1669| Type     | Description                 |
1670| ------- | ------------------- |
1671| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1672
1673**Example**
1674
1675```js
1676let hfpAg : bluetooth.HandsFreeAudioGatewayProfile = bluetooth.getProfile(bluetooth.ProfileId
1677    .PROFILE_HANDS_FREE_AUDIO_GATEWAY);
1678let ret : boolean = hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
1679```
1680
1681
1682### on('connectionStateChange')<sup>8+</sup><sup>(deprecated)</sup>
1683
1684on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
1685
1686Subscribes to the HFP connection state changes.
1687
1688> **NOTE**<br>
1689> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.on('connectionStateChange')](js-apis-bluetoothManager.md#onconnectionstatechangedeprecated-1).
1690
1691**System capability**: SystemCapability.Communication.Bluetooth.Core
1692
1693**Parameters**
1694
1695| Name     | Type                                      | Mandatory  | Description                                      |
1696| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1697| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
1698| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes   | Callback invoked to return the HFP connection state change event.                              |
1699
1700**Return value**
1701
1702No value is returned.
1703
1704**Example**
1705
1706```js
1707function onReceiveEvent(data : bluetooth.StateChangeParam) {
1708    console.info('hfp state = '+ JSON.stringify(data));
1709}
1710let hfpAg : bluetooth.HandsFreeAudioGatewayProfile= bluetooth.getProfile(bluetooth.ProfileId
1711    .PROFILE_HANDS_FREE_AUDIO_GATEWAY);
1712hfpAg.on('connectionStateChange', onReceiveEvent);
1713```
1714
1715
1716### off('connectionStateChange')<sup>8+</sup><sup>(deprecated)</sup>
1717
1718off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
1719
1720Unsubscribes from the HFP connection state changes.
1721
1722> **NOTE**<br>
1723> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.off('connectionStateChange')](js-apis-bluetoothManager.md#offconnectionstatechangedeprecated-1).
1724
1725**System capability**: SystemCapability.Communication.Bluetooth.Core
1726
1727**Parameters**
1728
1729| Name     | Type                                      | Mandatory  | Description                                      |
1730| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1731| type     | string                                   | Yes   | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
1732| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No   | Callback for the HFP connection state change event.                              |
1733
1734**Return value**
1735
1736No value is returned.
1737
1738**Example**
1739
1740```js
1741function onReceiveEvent(data : bluetooth.StateChangeParam) {
1742    console.info('hfp state = '+ JSON.stringify(data));
1743}
1744let hfpAg : bluetooth.HandsFreeAudioGatewayProfile= bluetooth.getProfile(bluetooth.ProfileId
1745    .PROFILE_HANDS_FREE_AUDIO_GATEWAY);
1746hfpAg.on('connectionStateChange', onReceiveEvent);
1747hfpAg.off('connectionStateChange', onReceiveEvent);
1748```
1749
1750
1751## GattServer
1752
1753Implements the Generic Attribute Profile (GATT) server. Before using a method of this class, you need to create a **GattServer** instance using the **createGattServer()** method.
1754
1755
1756### startAdvertising<sup>(deprecated)</sup>
1757
1758startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void
1759
1760Starts BLE advertising.
1761
1762> **NOTE**<br>
1763> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.startAdvertising](js-apis-bluetoothManager.md#startadvertisingdeprecated).
1764
1765**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1766
1767**System capability**: SystemCapability.Communication.Bluetooth.Core
1768
1769**Parameters**
1770
1771| Name        | Type                                   | Mandatory  | Description            |
1772| ----------- | ------------------------------------- | ---- | -------------- |
1773| setting     | [AdvertiseSetting](#advertisesetting) | Yes   | Settings related to BLE advertising.   |
1774| advData     | [AdvertiseData](#advertisedata)       | Yes   | Content of the BLE advertisement packet.     |
1775| advResponse | [AdvertiseData](#advertisedata)       | No   | Response to the BLE scan request.|
1776
1777**Return value**
1778
1779No value is returned.
1780
1781**Example**
1782
1783```js
1784let manufactureValueBuffer = new Uint8Array(4);
1785manufactureValueBuffer[0] = 1;
1786manufactureValueBuffer[1] = 2;
1787manufactureValueBuffer[2] = 3;
1788manufactureValueBuffer[3] = 4;
1789
1790let serviceValueBuffer = new Uint8Array(4);
1791serviceValueBuffer[0] = 4;
1792serviceValueBuffer[1] = 6;
1793serviceValueBuffer[2] = 7;
1794serviceValueBuffer[3] = 8;
1795console.info('manufactureValueBuffer = '+ JSON.stringify(manufactureValueBuffer));
1796console.info('serviceValueBuffer = '+ JSON.stringify(serviceValueBuffer));
1797let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
1798let setting : bluetooth.AdvertiseSetting = {
1799    interval:150,
1800    txPower:60,
1801    connectable:true,
1802}
1803
1804let manufactureData : bluetooth.ManufactureData = {
1805    manufactureId:4567,
1806    manufactureValue:manufactureValueBuffer.buffer
1807}
1808
1809let serviceData : bluetooth.ServiceData = {
1810    serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
1811    serviceValue:serviceValueBuffer.buffer
1812}
1813
1814let advData : bluetooth.AdvertiseData = {
1815    serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
1816    manufactureData:[manufactureData],
1817    serviceData:[serviceData],
1818}
1819
1820let advResponse : bluetooth.AdvertiseData = {
1821    serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
1822    manufactureData:[manufactureData],
1823    serviceData:[serviceData],
1824}
1825gattServer.startAdvertising(setting, advData, advResponse);
1826```
1827
1828
1829### stopAdvertising<sup>(deprecated)</sup>
1830
1831stopAdvertising(): void
1832
1833Stops BLE advertising.
1834
1835> **NOTE**<br>
1836> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.stopAdvertising](js-apis-bluetoothManager.md#stopadvertisingdeprecated).
1837
1838**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
1839
1840**System capability**: SystemCapability.Communication.Bluetooth.Core
1841
1842**Return value**
1843
1844No value is returned.
1845
1846**Example**
1847
1848```js
1849let server : bluetooth.GattServer = bluetooth.BLE.createGattServer();
1850server.stopAdvertising();
1851```
1852
1853
1854### addService<sup>(deprecated)</sup>
1855
1856addService(service: GattService): boolean
1857
1858Adds a service to this GATT server.
1859
1860> **NOTE**<br>
1861> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.addService](js-apis-bluetoothManager.md#addservicedeprecated).
1862
1863**Required permissions**: ohos.permission.USE_BLUETOOTH
1864
1865**System capability**: SystemCapability.Communication.Bluetooth.Core
1866
1867**Parameters**
1868
1869| Name    | Type                         | Mandatory  | Description                      |
1870| ------- | --------------------------- | ---- | ------------------------ |
1871| service | [GattService](#gattservice) | Yes   | Service to add. Settings related to BLE advertising.|
1872
1873**Return value**
1874
1875| Type     | Description                        |
1876| ------- | -------------------------- |
1877| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1878
1879**Example**
1880
1881```js
1882// Create descriptors.
1883let descriptors : Array<bluetooth.BLEDescriptor> = [];
1884let arrayBuffer = new ArrayBuffer(8);
1885let descV = new Uint8Array(arrayBuffer);
1886descV[0] = 11;
1887let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
1888  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
1889  descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
1890descriptors[0] = descriptor;
1891
1892// Create characteristics.
1893let characteristics : Array<bluetooth.BLECharacteristic> = [];
1894let arrayBufferC = new ArrayBuffer(8);
1895let cccV = new Uint8Array(arrayBufferC);
1896cccV[0] = 1;
1897let characteristic : bluetooth.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
1898  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
1899let characteristicN : bluetooth.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
1900  characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
1901characteristics[0] = characteristic;
1902
1903// Create a gattService instance.
1904let gattService : bluetooth.GattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, characteristics:characteristics, includeServices:[]};
1905
1906let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
1907let ret : boolean = gattServer.addService(gattService);
1908if (ret) {
1909   console.log("add service successfully");
1910} else {
1911   console.log("add service failed");
1912}
1913```
1914
1915
1916### removeService<sup>(deprecated)</sup>
1917
1918removeService(serviceUuid: string): boolean
1919
1920Removes a service from this GATT server.
1921
1922> **NOTE**<br>
1923> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.removeService](js-apis-bluetoothManager.md#removeservicedeprecated).
1924
1925**Required permissions**: ohos.permission.USE_BLUETOOTH
1926
1927**System capability**: SystemCapability.Communication.Bluetooth.Core
1928
1929**Parameters**
1930
1931| Name        | Type    | Mandatory  | Description                                      |
1932| ----------- | ------ | ---- | ---------------------------------------- |
1933| serviceUuid | string | Yes   | Universally unique identifier (UUID) of the service to remove, for example, **00001810-0000-1000-8000-00805F9B34FB**.|
1934
1935**Return value**
1936
1937| Type     | Description                        |
1938| ------- | -------------------------- |
1939| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1940
1941**Example**
1942
1943```js
1944let server : bluetooth.GattServer = bluetooth.BLE.createGattServer();
1945server.removeService('00001810-0000-1000-8000-00805F9B34FB');
1946```
1947
1948
1949### close<sup>(deprecated)</sup>
1950
1951close(): void
1952
1953Closes this GATT server to unregister it from the protocol stack. After this method is called, this [GattServer](#gattserver) cannot be used.
1954
1955> **NOTE**<br>
1956> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.close](js-apis-bluetoothManager.md#closedeprecated).
1957
1958**Required permissions**: ohos.permission.USE_BLUETOOTH
1959
1960**System capability**: SystemCapability.Communication.Bluetooth.Core
1961
1962**Example**
1963
1964```js
1965let server : bluetooth.GattServer = bluetooth.BLE.createGattServer();
1966server.close();
1967```
1968
1969
1970### notifyCharacteristicChanged<sup>(deprecated)</sup>
1971
1972notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): boolean
1973
1974Notifies the connected client device when a characteristic value changes.
1975
1976> **NOTE**<br>
1977> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.notifyCharacteristicChanged](js-apis-bluetoothManager.md#notifycharacteristicchangeddeprecated).
1978
1979**Required permissions**: ohos.permission.USE_BLUETOOTH
1980
1981**System capability**: SystemCapability.Communication.Bluetooth.Core
1982
1983**Parameters**
1984
1985| Name                 | Type                                      | Mandatory  | Description                                     |
1986| -------------------- | ---------------------------------------- | ---- | --------------------------------------- |
1987| deviceId             | string                                   | Yes   | Address of the client that receives notifications, for example, XX:XX:XX:XX:XX:XX.|
1988| notifyCharacteristic | [NotifyCharacteristic](#notifycharacteristic) | Yes   | New characteristic value.                              |
1989
1990**Return value**
1991
1992| Type     | Description                      |
1993| ------- | ------------------------ |
1994| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1995
1996**Example**
1997
1998```js
1999// Create descriptors.
2000let descriptors : Array<bluetooth.BLEDescriptor> = [];
2001let arrayBuffer = new ArrayBuffer(8);
2002let descV = new Uint8Array(arrayBuffer);
2003descV[0] = 11;
2004let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2005  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2006  descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
2007descriptors[0] = descriptor;
2008let arrayBufferC = new ArrayBuffer(8);
2009let characteristic : bluetooth.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2010  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
2011let notifyCharacteristic : bluetooth.NotifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2012  characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false};
2013let server : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2014server.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacteristic);
2015```
2016
2017
2018### sendResponse<sup>(deprecated)</sup>
2019
2020sendResponse(serverResponse: ServerResponse): boolean
2021
2022Sends a response to a read or write request from the GATT client.
2023
2024> **NOTE**<br>
2025> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.sendResponse](js-apis-bluetoothManager.md#sendresponsedeprecated).
2026
2027**Required permissions**: ohos.permission.USE_BLUETOOTH
2028
2029**System capability**: SystemCapability.Communication.Bluetooth.Core
2030
2031**Parameters**
2032
2033| Name           | Type                               | Mandatory  | Description             |
2034| -------------- | --------------------------------- | ---- | --------------- |
2035| serverResponse | [ServerResponse](#serverresponse) | Yes   | Response returned by the GATT server.|
2036
2037**Return value**
2038
2039| Type     | Description                        |
2040| ------- | -------------------------- |
2041| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
2042
2043**Example**
2044
2045```js
2046/* send response */
2047let arrayBufferCCC = new ArrayBuffer(8);
2048let cccValue = new Uint8Array(arrayBufferCCC);
2049cccValue[0] = 1123;
2050let serverResponse : bluetooth.ServerResponse = {
2051    "deviceId": "XX:XX:XX:XX:XX:XX",
2052    "transId": 0,
2053    "status": 0,
2054    "offset": 0,
2055    "value": arrayBufferCCC,
2056};
2057
2058let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2059let ret : boolean = gattServer.sendResponse(serverResponse);
2060if (ret) {
2061  console.log('bluetooth sendResponse successfully');
2062} else {
2063  console.log('bluetooth sendResponse failed');
2064}
2065```
2066
2067
2068### on('characteristicRead')<sup>(deprecated)</sup>
2069
2070on(type: "characteristicRead", callback: Callback&lt;CharacteristicReadReq&gt;): void
2071
2072Subscribes to the characteristic read request events.
2073
2074> **NOTE**<br>
2075> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('characteristicRead')](js-apis-bluetoothManager.md#oncharacteristicreaddeprecated).
2076
2077**Required permissions**: ohos.permission.USE_BLUETOOTH
2078
2079**System capability**: SystemCapability.Communication.Bluetooth.Core
2080
2081**Parameters**
2082
2083| Name     | Type                                      | Mandatory  | Description                                   |
2084| -------- | ---------------------------------------- | ---- | ------------------------------------- |
2085| type     | string                                   | Yes   | Event type. The value **characteristicRead** indicates a characteristic read request event.|
2086| callback | Callback&lt;[CharacteristicReadReq](#characteristicreadreq)&gt; | Yes   | Callback invoked to return a characteristic read request event from the GATT client.           |
2087
2088**Return value**
2089
2090No value is returned.
2091
2092**Example**
2093
2094```js
2095let arrayBufferCCC = new ArrayBuffer(8);
2096let cccValue = new Uint8Array(arrayBufferCCC);
2097cccValue[0] = 1123;
2098function ReadCharacteristicReq(CharacteristicReadReq : bluetooth.CharacteristicReadReq) {
2099  let deviceId : string = CharacteristicReadReq.deviceId;
2100  let transId : number = CharacteristicReadReq.transId;
2101  let offset : number = CharacteristicReadReq.offset;
2102  let characteristicUuid : string = CharacteristicReadReq.characteristicUuid;
2103
2104  let serverResponse : bluetooth.ServerResponse = {deviceId: deviceId, transId: transId, status: 0,
2105  offset: offset, value:arrayBufferCCC};
2106
2107  let ret : boolean = gattServer.sendResponse(serverResponse);
2108  if (ret) {
2109    console.log('bluetooth sendResponse successfully');
2110  } else {
2111    console.log('bluetooth sendResponse failed');
2112  }
2113}
2114
2115let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2116gattServer.on("characteristicRead", ReadCharacteristicReq);
2117```
2118
2119
2120### off('characteristicRead')<sup>(deprecated)</sup>
2121
2122off(type: "characteristicRead", callback?: Callback&lt;CharacteristicReadReq&gt;): void
2123
2124Unsubscribes from the characteristic read request events.
2125
2126> **NOTE**<br>
2127> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('characteristicRead')](js-apis-bluetoothManager.md#offcharacteristicreaddeprecated).
2128
2129**Required permissions**: ohos.permission.USE_BLUETOOTH
2130
2131**System capability**: SystemCapability.Communication.Bluetooth.Core
2132
2133**Parameters**
2134
2135| Name     | Type                                      | Mandatory  | Description                                      |
2136| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2137| type     | string                                   | Yes   | Event type. The value **characteristicRead** indicates a characteristic read request event.   |
2138| callback | Callback&lt;[CharacteristicReadReq](#characteristicreadreq)&gt; | No   | Callback for the characteristic read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
2139
2140**Return value**
2141
2142No value is returned.
2143
2144**Example**
2145
2146```js
2147let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2148gattServer.off("characteristicRead");
2149```
2150
2151
2152### on('characteristicWrite')<sup>(deprecated)</sup>
2153
2154on(type: "characteristicWrite", callback: Callback&lt;CharacteristicWriteReq&gt;): void
2155
2156Subscribes to the characteristic write request events.
2157
2158> **NOTE**<br>
2159> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('characteristicWrite')](js-apis-bluetoothManager.md#oncharacteristicwritedeprecated).
2160
2161**Required permissions**: ohos.permission.USE_BLUETOOTH
2162
2163**System capability**: SystemCapability.Communication.Bluetooth.Core
2164
2165**Parameters**
2166
2167| Name     | Type                                      | Mandatory  | Description                                    |
2168| -------- | ---------------------------------------- | ---- | -------------------------------------- |
2169| type     | string                                   | Yes   | Event type. The value **characteristicWrite** indicates a characteristic write request event.|
2170| callback | Callback&lt;[CharacteristicWriteReq](#characteristicwritereq)&gt; | Yes   | Callback invoked to return a characteristic write request from the GATT client.            |
2171
2172**Return value**
2173
2174No value is returned.
2175
2176**Example**
2177
2178```js
2179let arrayBufferCCC = new ArrayBuffer(8);
2180let cccValue = new Uint8Array(arrayBufferCCC);
2181function WriteCharacteristicReq(CharacteristicWriteReq : bluetooth.CharacteristicWriteReq) {
2182  let deviceId : string = CharacteristicWriteReq.deviceId;
2183  let transId : number = CharacteristicWriteReq.transId;
2184  let offset : number = CharacteristicWriteReq.offset;
2185  let isPrep : boolean = CharacteristicWriteReq.isPrep;
2186  let needRsp : boolean = CharacteristicWriteReq.needRsp;
2187  let value =  new Uint8Array(arrayBufferCCC);
2188  let characteristicUuid : string = CharacteristicWriteReq.characteristicUuid;
2189
2190  cccValue.set(new Uint8Array(value));
2191  let serverResponse : bluetooth.ServerResponse = {deviceId: deviceId, transId: transId, status: 0,
2192  offset: offset, value:arrayBufferCCC};
2193
2194  let ret : boolean = gattServer.sendResponse(serverResponse);
2195  if (ret) {
2196    console.log('bluetooth sendResponse successfully');
2197  } else {
2198    console.log('bluetooth sendResponse failed');
2199  }
2200}
2201
2202let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2203gattServer.on("characteristicWrite", WriteCharacteristicReq);
2204```
2205
2206
2207### off('characteristicWrite')<sup>(deprecated)</sup>
2208
2209off(type: "characteristicWrite", callback?: Callback&lt;CharacteristicWriteReq&gt;): void
2210
2211Unsubscribes from the characteristic write request events.
2212
2213> **NOTE**<br>
2214> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('characteristicWrite')](js-apis-bluetoothManager.md#offcharacteristicwritedeprecated).
2215
2216**Required permissions**: ohos.permission.USE_BLUETOOTH
2217
2218**System capability**: SystemCapability.Communication.Bluetooth.Core
2219
2220**Parameters**
2221
2222| Name     | Type                                      | Mandatory  | Description                                      |
2223| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2224| type     | string                                   | Yes   | Event type. The value **characteristicWrite** indicates a characteristic write request event.  |
2225| callback | Callback&lt;[CharacteristicWriteReq](#characteristicwritereq)&gt; | No   | Callback for the characteristic write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
2226
2227**Return value**
2228
2229No value is returned.
2230
2231**Example**
2232
2233```js
2234let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2235gattServer.off("characteristicWrite");
2236```
2237
2238
2239### on('descriptorRead')<sup>(deprecated)</sup>
2240
2241on(type: "descriptorRead", callback: Callback&lt;DescriptorReadReq&gt;): void
2242
2243Subscribes to the descriptor read request events.
2244
2245> **NOTE**<br>
2246> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('descriptorRead')](js-apis-bluetoothManager.md#ondescriptorreaddeprecated).
2247
2248**Required permissions**: ohos.permission.USE_BLUETOOTH
2249
2250**System capability**: SystemCapability.Communication.Bluetooth.Core
2251
2252**Parameters**
2253
2254| Name     | Type                                      | Mandatory  | Description                               |
2255| -------- | ---------------------------------------- | ---- | --------------------------------- |
2256| type     | string                                   | Yes   | Event type. The value **descriptorRead** indicates a descriptor read request event.|
2257| callback | Callback&lt;[DescriptorReadReq](#descriptorreadreq)&gt; | Yes   | Callback invoked to return a descriptor read request event from the GATT client.       |
2258
2259**Return value**
2260
2261No value is returned.
2262
2263**Example**
2264
2265```js
2266let arrayBufferDesc = new ArrayBuffer(8);
2267let descValue = new Uint8Array(arrayBufferDesc);
2268descValue[0] = 1101;
2269function ReadDescriptorReq(DescriptorReadReq : bluetooth.DescriptorReadReq) {
2270  let deviceId : string = DescriptorReadReq.deviceId;
2271  let transId : number = DescriptorReadReq.transId;
2272  let offset : number = DescriptorReadReq.offset;
2273  let descriptorUuid : string = DescriptorReadReq.descriptorUuid;
2274
2275  let serverResponse : bluetooth.ServerResponse = {deviceId: deviceId, transId: transId, status: 0,
2276  offset: offset, value:arrayBufferDesc};
2277
2278  let ret : boolean = gattServer.sendResponse(serverResponse);
2279  if (ret) {
2280    console.log('bluetooth sendResponse successfully');
2281  } else {
2282    console.log('bluetooth sendResponse failed');
2283  }
2284}
2285
2286let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2287gattServer.on("descriptorRead", ReadDescriptorReq);
2288```
2289
2290
2291### off('descriptorRead')<sup>(deprecated)</sup>
2292
2293off(type: "descriptorRead", callback?: Callback&lt;DescriptorReadReq&gt;): void
2294
2295Unsubscribes from the descriptor read request events.
2296
2297> **NOTE**<br>
2298> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('descriptorRead')](js-apis-bluetoothManager.md#offdescriptorreaddeprecated).
2299
2300**Required permissions**: ohos.permission.USE_BLUETOOTH
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 **descriptorRead** indicates a descriptor read request event.       |
2309| callback | Callback&lt;[DescriptorReadReq](#descriptorreadreq)&gt; | No   | Callback for the descriptor read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
2310
2311**Return value**
2312
2313No value is returned.
2314
2315**Example**
2316
2317```js
2318let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2319gattServer.off("descriptorRead");
2320```
2321
2322
2323### on('descriptorWrite')<sup>(deprecated)</sup>
2324
2325on(type: "descriptorWrite", callback: Callback&lt;DescriptorWriteReq&gt;): void
2326
2327Subscribes to the descriptor write request events.
2328
2329> **NOTE**<br>
2330> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('descriptorWrite')](js-apis-bluetoothManager.md#ondescriptorwritedeprecated).
2331
2332**Required permissions**: ohos.permission.USE_BLUETOOTH
2333
2334**System capability**: SystemCapability.Communication.Bluetooth.Core
2335
2336**Parameters**
2337
2338| Name     | Type                                      | Mandatory  | Description                                |
2339| -------- | ---------------------------------------- | ---- | ---------------------------------- |
2340| type     | string                                   | Yes   | Event type. The value **descriptorWrite** indicates a descriptor write request event.|
2341| callback | Callback&lt;[DescriptorWriteReq](#descriptorwritereq)&gt; | Yes   | Callback invoked to return a descriptor write request from the GATT client.        |
2342
2343**Return value**
2344
2345No value is returned.
2346
2347**Example**
2348
2349```js
2350let arrayBufferDesc = new ArrayBuffer(8);
2351let descValue = new Uint8Array(arrayBufferDesc);
2352function WriteDescriptorReq(DescriptorWriteReq : bluetooth.DescriptorWriteReq) {
2353  let deviceId : string = DescriptorWriteReq.deviceId;
2354  let transId : number = DescriptorWriteReq.transId;
2355  let offset : number = DescriptorWriteReq.offset;
2356  let isPrep : boolean = DescriptorWriteReq.isPrep;
2357  let needRsp : boolean = DescriptorWriteReq.needRsp;
2358  let value = new Uint8Array(arrayBufferDesc);
2359  let descriptorUuid : string = DescriptorWriteReq.descriptorUuid;
2360
2361  descValue.set(new Uint8Array(value));
2362  let serverResponse : bluetooth.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
2363
2364  let ret : boolean = gattServer.sendResponse(serverResponse);
2365  if (ret) {
2366    console.log('bluetooth sendResponse successfully');
2367  } else {
2368    console.log('bluetooth sendResponse failed');
2369  }
2370}
2371
2372let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2373gattServer.on("descriptorWrite", WriteDescriptorReq);
2374```
2375
2376
2377### off('descriptorWrite')<sup>(deprecated)</sup>
2378
2379off(type: "descriptorWrite", callback?: Callback&lt;DescriptorWriteReq&gt;): void
2380
2381Unsubscribes from the descriptor write request events.
2382
2383> **NOTE**<br>
2384> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('descriptorWrite')](js-apis-bluetoothManager.md#offdescriptorwritedeprecated).
2385
2386**Required permissions**: ohos.permission.USE_BLUETOOTH
2387
2388**System capability**: SystemCapability.Communication.Bluetooth.Core
2389
2390**Parameters**
2391
2392| Name     | Type                                      | Mandatory  | Description                                      |
2393| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2394| type     | string                                   | Yes   | Event type. The value **descriptorWrite** indicates a descriptor write request event.      |
2395| callback | Callback&lt;[DescriptorWriteReq](#descriptorwritereq)&gt; | No   | Callback for the descriptor write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
2396
2397**Return value**
2398
2399No value is returned.
2400
2401**Example**
2402
2403```js
2404let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2405gattServer.off("descriptorWrite");
2406```
2407
2408
2409### on('connectStateChange')<sup>(deprecated)</sup>
2410
2411on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
2412
2413Subscribes to the BLE connection state changes.
2414
2415> **NOTE**<br>
2416> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('connectStateChange')](js-apis-bluetoothManager.md#onconnectstatechangedeprecated).
2417
2418**Required permissions**: ohos.permission.USE_BLUETOOTH
2419
2420**System capability**: SystemCapability.Communication.Bluetooth.Core
2421
2422**Parameters**
2423
2424| Name     | Type                                      | Mandatory  | Description                                      |
2425| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2426| type     | string                                   | Yes   | Event type. The value **connectStateChange** indicates a BLE connection state change event.|
2427| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | Yes   | Callback invoked to return the BLE connection state.                         |
2428
2429**Return value**
2430
2431No value is returned.
2432
2433**Example**
2434
2435```js
2436function Connected(BLEConnectChangedState : bluetooth.BLEConnectChangedState) {
2437  let deviceId : string = BLEConnectChangedState.deviceId;
2438  let status : bluetooth.ProfileConnectionState = BLEConnectChangedState.state;
2439}
2440
2441let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2442gattServer.on("connectStateChange", Connected);
2443```
2444
2445
2446### off('connectStateChange')<sup>(deprecated)</sup>
2447
2448off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
2449
2450Unsubscribes from the BLE connection state changes.
2451
2452> **NOTE**<br>
2453> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('connectStateChange')](js-apis-bluetoothManager.md#offconnectstatechangedeprecated).
2454
2455**Required permissions**: ohos.permission.USE_BLUETOOTH
2456
2457**System capability**: SystemCapability.Communication.Bluetooth.Core
2458
2459**Parameters**
2460
2461| Name     | Type                                      | Mandatory  | Description                                      |
2462| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2463| type     | string                                   | Yes   | Event type. The value **connectStateChange** indicates a BLE connection state change event.|
2464| 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**.|
2465
2466**Return value**
2467
2468No value is returned.
2469
2470**Example**
2471
2472```js
2473let gattServer : bluetooth.GattServer = bluetooth.BLE.createGattServer();
2474gattServer.off("connectStateChange");
2475```
2476
2477
2478## GattClientDevice
2479
2480Implements the GATT client. Before using a method of this class, you must create a **GattClientDevice** instance using the **createGattClientDevice(deviceId: string)** method.
2481
2482
2483### connect<sup>(deprecated)</sup>
2484
2485connect(): boolean
2486
2487Initiates a connection to the remote BLE device.
2488
2489> **NOTE**<br>
2490> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.connect](js-apis-bluetoothManager.md#connectdeprecated-1).
2491
2492**Required permissions**: ohos.permission.USE_BLUETOOTH
2493
2494**System capability**: SystemCapability.Communication.Bluetooth.Core
2495
2496**Return value**
2497
2498| Type     | Description                       |
2499| ------- | ------------------------- |
2500| boolean | Returns **true** if the connection is successful; returns **false** otherwise.|
2501
2502**Example**
2503
2504```js
2505let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2506let ret : boolean = device.connect();
2507```
2508
2509
2510### disconnect<sup>(deprecated)</sup>
2511
2512disconnect(): boolean
2513
2514Disconnects from the remote BLE device.
2515
2516> **NOTE**<br>
2517> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.disconnect](js-apis-bluetoothManager.md#disconnectdeprecated-4).
2518
2519**Required permissions**: ohos.permission.USE_BLUETOOTH
2520
2521**System capability**: SystemCapability.Communication.Bluetooth.Core
2522
2523**Return value**
2524
2525| Type     | Description                          |
2526| ------- | ---------------------------- |
2527| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
2528
2529**Example**
2530
2531```js
2532let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2533let ret : boolean = device.disconnect();
2534```
2535
2536
2537### close<sup>(deprecated)</sup>
2538
2539close(): boolean
2540
2541Closes this GATT client to unregister it from the protocol stack. After this method is called, this [GattClientDevice](#gattclientdevice) instance cannot be used.
2542
2543> **NOTE**<br>
2544> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.close](js-apis-bluetoothManager.md#closedeprecated-1).
2545
2546**Required permissions**: ohos.permission.USE_BLUETOOTH
2547
2548**System capability**: SystemCapability.Communication.Bluetooth.Core
2549
2550**Return value**
2551
2552| Type     | Description                        |
2553| ------- | -------------------------- |
2554| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
2555
2556**Example**
2557
2558```js
2559let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2560let ret : boolean = device.close();
2561```
2562
2563
2564
2565
2566### getServices<sup>(deprecated)</sup>
2567
2568getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void
2569
2570Obtains all services of the remote BLE device. This API uses an asynchronous callback to return the result.
2571
2572> **NOTE**<br>
2573> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getServices](js-apis-bluetoothManager.md#getservicesdeprecated).
2574
2575**Required permissions**: ohos.permission.USE_BLUETOOTH
2576
2577**System capability**: SystemCapability.Communication.Bluetooth.Core
2578
2579**Parameters**
2580
2581| Name     | Type                                      | Mandatory  | Description                      |
2582| -------- | ---------------------------------------- | ---- | ------------------------ |
2583| callback | AsyncCallback&lt;Array&lt;[GattService](#gattservice)&gt;&gt; | Yes   | Callback invoked to return the services obtained.|
2584
2585**Return value**
2586
2587No value is returned.
2588
2589**Example**
2590
2591```js
2592import { BusinessError } from '@ohos.base';
2593// Callback
2594function getServices(code : BusinessError, gattServices : Array<bluetooth.GattService>) {
2595  if (code.code == 0) {
2596      let services : Array<bluetooth.GattService> = gattServices;
2597      console.log('bluetooth code is ' + code.code);
2598      console.log("bluetooth services size is ", services.length);
2599
2600      for (let i = 0; i < services.length; i++) {
2601        console.log('bluetooth serviceUuid is ' + services[i].serviceUuid);
2602      }
2603  }
2604}
2605
2606let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2607device.connect();
2608device.getServices(getServices);
2609```
2610
2611
2612### getServices<sup>(deprecated)</sup>
2613
2614getServices(): Promise&lt;Array&lt;GattService&gt;&gt;
2615
2616Obtains all services of the remote BLE device. This API uses a promise to return the result.
2617
2618> **NOTE**<br>
2619> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getServices](js-apis-bluetoothManager.md#getservicesdeprecated-1).
2620
2621**Required permissions**: ohos.permission.USE_BLUETOOTH
2622
2623**System capability**: SystemCapability.Communication.Bluetooth.Core
2624
2625**Return value**
2626
2627| Type                                      | Description                         |
2628| ---------------------------------------- | --------------------------- |
2629| Promise&lt;Array&lt;[GattService](#gattservice)&gt;&gt; | Promise used to return the services obtained.|
2630
2631**Example**
2632
2633```js
2634// Promise
2635let device : bluetooth.GattClientDevice= bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2636device.connect();
2637device.getServices().then((result : Array<bluetooth.GattService>) => {
2638    console.info("getServices successfully:" + JSON.stringify(result));
2639});
2640```
2641
2642
2643### readCharacteristicValue<sup>(deprecated)</sup>
2644
2645readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void
2646
2647Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
2648
2649> **NOTE**<br>
2650> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.readCharacteristicValue](js-apis-bluetoothManager.md#readcharacteristicvaluedeprecated).
2651
2652**Required permissions**: ohos.permission.USE_BLUETOOTH
2653
2654**System capability**: SystemCapability.Communication.Bluetooth.Core
2655
2656**Parameters**
2657
2658| Name           | Type                                      | Mandatory  | Description                     |
2659| -------------- | ---------------------------------------- | ---- | ----------------------- |
2660| characteristic | [BLECharacteristic](#blecharacteristic)  | Yes   | Characteristic value to read.               |
2661| callback       | AsyncCallback&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes   | Callback invoked to return the characteristic value read.|
2662
2663**Return value**
2664
2665No value is returned.
2666
2667**Example**
2668
2669```js
2670import { BusinessError } from '@ohos.base';
2671function readCcc(code : BusinessError, BLECharacteristic : bluetooth.BLECharacteristic) {
2672  if (code.code != 0) {
2673      return;
2674  }
2675  console.log('bluetooth characteristic uuid: ' + BLECharacteristic.characteristicUuid);
2676  let value = new Uint8Array(BLECharacteristic.characteristicValue);
2677  console.log('bluetooth characteristic value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
2678}
2679
2680let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2681let descriptors : Array<bluetooth.BLEDescriptor> = [];
2682let bufferDesc : ArrayBuffer = new ArrayBuffer(8);
2683let descV : Uint8Array = new Uint8Array(bufferDesc);
2684descV[0] = 11;
2685let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2686characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2687descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
2688descriptors[0] = descriptor;
2689
2690let bufferCCC = new ArrayBuffer(8);
2691let cccV = new Uint8Array(bufferCCC);
2692cccV[0] = 1;
2693let characteristic : bluetooth.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2694characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2695characteristicValue: bufferCCC, descriptors:descriptors};
2696
2697device.readCharacteristicValue(characteristic, readCcc);
2698```
2699
2700
2701### readCharacteristicValue<sup>(deprecated)</sup>
2702
2703readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt;
2704
2705Reads the characteristic value of the specific service of the remote BLE device. This API uses a promise to return the result.
2706
2707> **NOTE**<br>
2708> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.readCharacteristicValue](js-apis-bluetoothManager.md#readcharacteristicvaluedeprecated-1).
2709
2710**Required permissions**: ohos.permission.USE_BLUETOOTH
2711
2712**System capability**: SystemCapability.Communication.Bluetooth.Core
2713
2714**Parameters**
2715
2716| Name           | Type                                     | Mandatory  | Description      |
2717| -------------- | --------------------------------------- | ---- | -------- |
2718| characteristic | [BLECharacteristic](#blecharacteristic) | Yes   | Characteristic value to read.|
2719
2720**Return value**
2721
2722| Type                                      | Description                        |
2723| ---------------------------------------- | -------------------------- |
2724| Promise&lt;[BLECharacteristic](#blecharacteristic)&gt; | Promise used to return the characteristic value read.|
2725
2726**Example**
2727
2728```js
2729let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2730let descriptors : Array<bluetooth.BLEDescriptor> = [];
2731let bufferDesc = new ArrayBuffer(8);
2732let descV = new Uint8Array(bufferDesc);
2733descV[0] = 11;
2734let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2735characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2736descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
2737descriptors[0] = descriptor;
2738
2739let bufferCCC = new ArrayBuffer(8);
2740let cccV = new Uint8Array(bufferCCC);
2741cccV[0] = 1;
2742let characteristic : bluetooth.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2743characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2744characteristicValue: bufferCCC, descriptors:descriptors};
2745
2746device.readCharacteristicValue(characteristic);
2747```
2748
2749
2750### readDescriptorValue<sup>(deprecated)</sup>
2751
2752readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void
2753
2754Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
2755
2756> **NOTE**<br>
2757> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.readDescriptorValue](js-apis-bluetoothManager.md#readdescriptorvaluedeprecated).
2758
2759**Required permissions**: ohos.permission.USE_BLUETOOTH
2760
2761**System capability**: SystemCapability.Communication.Bluetooth.Core
2762
2763**Parameters**
2764
2765| Name       | Type                                      | Mandatory  | Description                     |
2766| ---------- | ---------------------------------------- | ---- | ----------------------- |
2767| descriptor | [BLEDescriptor](#bledescriptor)          | Yes   | Descriptor to read.               |
2768| callback   | AsyncCallback&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes   | Callback invoked to return the descriptor read.|
2769
2770**Return value**
2771
2772No value is returned.
2773
2774**Example**
2775
2776```js
2777import { BusinessError } from '@ohos.base';
2778function readDesc(code : BusinessError, BLEDescriptor : bluetooth.BLEDescriptor) {
2779  if (code.code != 0) {
2780      return;
2781  }
2782  console.log('bluetooth descriptor uuid: ' + BLEDescriptor.descriptorUuid);
2783  let value = new Uint8Array(BLEDescriptor.descriptorValue);
2784  console.log('bluetooth descriptor value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
2785}
2786
2787let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2788let bufferDesc = new ArrayBuffer(8);
2789let descV = new Uint8Array(bufferDesc);
2790descV[0] = 11;
2791let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2792  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2793  descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
2794device.readDescriptorValue(descriptor, readDesc);
2795```
2796
2797
2798### readDescriptorValue<sup>(deprecated)</sup>
2799
2800readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt;
2801
2802Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses a promise to return the result.
2803
2804> **NOTE**<br>
2805> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.readDescriptorValue](js-apis-bluetoothManager.md#readdescriptorvaluedeprecated-1).
2806
2807**Required permissions**: ohos.permission.USE_BLUETOOTH
2808
2809**System capability**: SystemCapability.Communication.Bluetooth.Core
2810
2811**Parameters**
2812
2813| Name       | Type                             | Mandatory  | Description      |
2814| ---------- | ------------------------------- | ---- | -------- |
2815| descriptor | [BLEDescriptor](#bledescriptor) | Yes   | Descriptor to read.|
2816
2817**Return value**
2818
2819| Type                                      | Description                        |
2820| ---------------------------------------- | -------------------------- |
2821| Promise&lt;[BLEDescriptor](#bledescriptor)&gt; | Promise used to return the descriptor read.|
2822
2823**Example**
2824
2825```js
2826let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2827let bufferDesc = new ArrayBuffer(8);
2828let descV = new Uint8Array(bufferDesc);
2829descV[0] = 11;
2830let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2831  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2832  descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
2833device.readDescriptorValue(descriptor);
2834```
2835
2836
2837### writeCharacteristicValue<sup>(deprecated)</sup>
2838
2839writeCharacteristicValue(characteristic: BLECharacteristic): boolean
2840
2841Writes a characteristic value to the remote BLE device.
2842
2843> **NOTE**<br>
2844> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.writeCharacteristicValue](js-apis-bluetoothManager.md#writecharacteristicvaluedeprecated).
2845
2846**Required permissions**: ohos.permission.USE_BLUETOOTH
2847
2848**System capability**: SystemCapability.Communication.Bluetooth.Core
2849
2850**Parameters**
2851
2852| Name           | Type                                     | Mandatory  | Description                 |
2853| -------------- | --------------------------------------- | ---- | ------------------- |
2854| characteristic | [BLECharacteristic](#blecharacteristic) | Yes   | Binary value and other parameters of the BLE device characteristic.|
2855
2856**Return value**
2857
2858| Type     | Description                         |
2859| ------- | --------------------------- |
2860| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
2861
2862**Example**
2863
2864```js
2865let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2866let descriptors : Array<bluetooth.BLEDescriptor> = [];
2867let bufferDesc = new ArrayBuffer(8);
2868let descV = new Uint8Array(bufferDesc);
2869descV[0] = 11;
2870let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2871  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2872  descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
2873descriptors[0] = descriptor;
2874
2875let bufferCCC = new ArrayBuffer(8);
2876let cccV = new Uint8Array(bufferCCC);
2877cccV[0] = 1;
2878let characteristic : bluetooth.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2879  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2880  characteristicValue: bufferCCC, descriptors:descriptors};
2881let retWriteCcc : boolean = device.writeCharacteristicValue(characteristic);
2882if (retWriteCcc) {
2883  console.log('write characteristic successfully');
2884} else {
2885  console.log('write characteristic failed');
2886}
2887```
2888
2889
2890### writeDescriptorValue<sup>(deprecated)</sup>
2891
2892writeDescriptorValue(descriptor: BLEDescriptor): boolean
2893
2894Writes binary data to the specific descriptor of the remote BLE device.
2895
2896> **NOTE**<br>
2897> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.writeDescriptorValue](js-apis-bluetoothManager.md#writedescriptorvaluedeprecated).
2898
2899**Required permissions**: ohos.permission.USE_BLUETOOTH
2900
2901**System capability**: SystemCapability.Communication.Bluetooth.Core
2902
2903**Parameters**
2904
2905| Name       | Type                             | Mandatory  | Description                |
2906| ---------- | ------------------------------- | ---- | ------------------ |
2907| descriptor | [BLEDescriptor](#bledescriptor) | Yes   | Binary value and other parameters of the BLE device descriptor.|
2908
2909**Return value**
2910
2911| Type     | Description                         |
2912| ------- | --------------------------- |
2913| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
2914
2915**Example**
2916
2917```js
2918let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2919let bufferDesc = new ArrayBuffer(8);
2920let descV = new Uint8Array(bufferDesc);
2921descV[0] = 22;
2922let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2923  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2924  descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
2925let retWriteDesc : boolean = device.writeDescriptorValue(descriptor);
2926if (retWriteDesc) {
2927  console.log('bluetooth write descriptor successfully');
2928} else {
2929  console.log('bluetooth write descriptor failed');
2930}
2931```
2932
2933
2934### setBLEMtuSize<sup>(deprecated)</sup>
2935
2936setBLEMtuSize(mtu: number): boolean
2937
2938Sets 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).
2939
2940> **NOTE**<br>
2941> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.setBLEMtuSize](js-apis-bluetoothManager.md#setblemtusizedeprecated).
2942
2943**Required permissions**: ohos.permission.USE_BLUETOOTH
2944
2945**System capability**: SystemCapability.Communication.Bluetooth.Core
2946
2947**Parameters**
2948
2949| Name | Type    | Mandatory  | Description            |
2950| ---- | ------ | ---- | -------------- |
2951| mtu  | number | Yes   | MTU to set, which ranges from 22 to 512 bytes.|
2952
2953**Return value**
2954
2955| Type     | Description                          |
2956| ------- | ---------------------------- |
2957| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
2958
2959**Example**
2960
2961```js
2962let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
2963device.setBLEMtuSize(128);
2964```
2965
2966
2967### setNotifyCharacteristicChanged<sup>(deprecated)</sup>
2968
2969setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): boolean
2970
2971Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
2972
2973> **NOTE**<br>
2974> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.setNotifyCharacteristicChanged](js-apis-bluetoothManager.md#setnotifycharacteristicchangeddeprecated).
2975
2976**Required permissions**: ohos.permission.USE_BLUETOOTH
2977
2978**System capability**: SystemCapability.Communication.Bluetooth.Core
2979
2980**Parameters**
2981
2982| Name           | Type                                     | Mandatory  | Description                           |
2983| -------------- | --------------------------------------- | ---- | ----------------------------- |
2984| characteristic | [BLECharacteristic](#blecharacteristic) | Yes   | BLE characteristic to listen for.                     |
2985| 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.|
2986
2987**Return value**
2988
2989| Type     | Description                       |
2990| ------- | ------------------------- |
2991| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
2992
2993**Example**
2994
2995```js
2996// Create descriptors.
2997let descriptors : Array<bluetooth.BLEDescriptor> = [];
2998let arrayBuffer = new ArrayBuffer(8);
2999let descV = new Uint8Array(arrayBuffer);
3000descV[0] = 11;
3001let descriptor : bluetooth.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3002  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3003  descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
3004descriptors[0] = descriptor;
3005let arrayBufferC = new ArrayBuffer(8);
3006let characteristic : bluetooth.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3007  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
3008let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3009device.setNotifyCharacteristicChanged(characteristic, false);
3010```
3011
3012
3013### on('BLECharacteristicChange')<sup>(deprecated)</sup>
3014
3015on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void
3016
3017Subscribes to the BLE characteristic changes. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called.
3018
3019> **NOTE**<br>
3020> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.on('BLECharacteristicChange')](js-apis-bluetoothManager.md#onblecharacteristicchangedeprecated).
3021
3022**Required permissions**: ohos.permission.USE_BLUETOOTH
3023
3024**System capability**: SystemCapability.Communication.Bluetooth.Core
3025
3026**Parameters**
3027
3028| Name     | Type                                      | Mandatory  | Description                                      |
3029| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3030| type     | string                                   | Yes   | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
3031| callback | Callback&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes   | Callback invoked to return the characteristic value changes.                 |
3032
3033**Return value**
3034
3035No value is returned.
3036
3037**Example**
3038
3039```js
3040function CharacteristicChange(CharacteristicChangeReq : bluetooth.BLECharacteristic) {
3041  let serviceUuid : string = CharacteristicChangeReq.serviceUuid;
3042  let characteristicUuid : string = CharacteristicChangeReq.characteristicUuid;
3043  let value = new Uint8Array(CharacteristicChangeReq.characteristicValue);
3044}
3045let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3046device.on('BLECharacteristicChange', CharacteristicChange);
3047```
3048
3049
3050### off('BLECharacteristicChange')<sup>(deprecated)</sup>
3051
3052off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void
3053
3054Unsubscribes from the BLE characteristic changes.
3055
3056> **NOTE**<br>
3057> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.off('BLECharacteristicChange')](js-apis-bluetoothManager.md#offblecharacteristicchangedeprecated).
3058
3059**Required permissions**: ohos.permission.USE_BLUETOOTH
3060
3061**System capability**: SystemCapability.Communication.Bluetooth.Core
3062
3063**Parameters**
3064
3065| Name     | Type                                      | Mandatory  | Description                                      |
3066| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3067| type     | string                                   | Yes   | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
3068| 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**.|
3069
3070**Return value**
3071
3072No value is returned.
3073
3074**Example**
3075
3076```js
3077let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3078device.off('BLECharacteristicChange');
3079```
3080
3081
3082### on('BLEConnectionStateChange')<sup>(deprecated)</sup>
3083
3084on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
3085
3086Subscribes to the BLE connection state changes.
3087
3088> **NOTE**<br>
3089> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.on('BLEConnectionStateChange')](js-apis-bluetoothManager.md#onbleconnectionstatechangedeprecated).
3090
3091**Required permissions**: ohos.permission.USE_BLUETOOTH
3092
3093**System capability**: SystemCapability.Communication.Bluetooth.Core
3094
3095**Parameters**
3096
3097| Name     | Type                                      | Mandatory  | Description                                      |
3098| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3099| type     | string                                   | Yes   | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
3100| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | Yes   | Callback invoked to return the BLE connection state.                          |
3101
3102**Return value**
3103
3104No value is returned.
3105
3106**Example**
3107
3108```js
3109function ConnectStateChanged(state : bluetooth.BLEConnectChangedState) {
3110  console.log('bluetooth connect state changed');
3111  let connectState : bluetooth.ProfileConnectionState = state.state;
3112}
3113let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3114device.on('BLEConnectionStateChange', ConnectStateChanged);
3115```
3116
3117
3118### off('BLEConnectionStateChange')<sup>(deprecated)</sup>
3119
3120off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
3121
3122Unsubscribes from the BLE connection state changes.
3123
3124> **NOTE**<br>
3125> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.off('BLEConnectionStateChange')](js-apis-bluetoothManager.md#offbleconnectionstatechangedeprecated).
3126
3127**Required permissions**: ohos.permission.USE_BLUETOOTH
3128
3129**System capability**: SystemCapability.Communication.Bluetooth.Core
3130
3131**Parameters**
3132
3133| Name     | Type                                      | Mandatory  | Description                                      |
3134| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3135| type     | string                                   | Yes   | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
3136| 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**.|
3137
3138**Return value**
3139
3140No value is returned.
3141
3142**Example**
3143
3144```js
3145let device : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3146device.off('BLEConnectionStateChange');
3147```
3148
3149
3150### getDeviceName<sup>(deprecated)</sup>
3151
3152getDeviceName(callback: AsyncCallback&lt;string&gt;): void
3153
3154Obtains the name of the remote BLE device. This API uses an asynchronous callback to return the result.
3155
3156> **NOTE**<br>
3157> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getDeviceName](js-apis-bluetoothManager.md#getdevicenamedeprecated).
3158
3159**Required permissions**: ohos.permission.USE_BLUETOOTH
3160
3161**System capability**: SystemCapability.Communication.Bluetooth.Core
3162
3163**Parameters**
3164
3165| Name     | Type                         | Mandatory  | Description                             |
3166| -------- | --------------------------- | ---- | ------------------------------- |
3167| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the remote BLE device name obtained.|
3168
3169**Return value**
3170
3171No value is returned.
3172
3173**Example**
3174
3175```js
3176import { BusinessError } from '@ohos.base';
3177// callback
3178let gattClient : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
3179let deviceName : void = gattClient.getDeviceName((err : BusinessError, data : string)=> {
3180    console.info('device name err ' + JSON.stringify(err));
3181    console.info('device name' + JSON.stringify(data));
3182})
3183```
3184
3185
3186### getDeviceName<sup>(deprecated)</sup>
3187
3188getDeviceName(): Promise&lt;string&gt;
3189
3190Obtains the name of the remote BLE device. This API uses a promise to return the result.
3191
3192> **NOTE**<br>
3193> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getDeviceName](js-apis-bluetoothManager.md#getdevicenamedeprecated-1).
3194
3195**Required permissions**: ohos.permission.USE_BLUETOOTH
3196
3197**System capability**: SystemCapability.Communication.Bluetooth.Core
3198
3199**Return value**
3200
3201| Type                   | Description                                |
3202| --------------------- | ---------------------------------- |
3203| Promise&lt;string&gt; | Promise used to return the remote BLE device name.|
3204
3205**Example**
3206
3207```js
3208// promise
3209let gattClient : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
3210gattClient.getDeviceName().then((data) => {
3211    console.info('device name' + JSON.stringify(data));
3212})
3213```
3214
3215
3216### getRssiValue<sup>(deprecated)</sup>
3217
3218getRssiValue(callback: AsyncCallback&lt;number&gt;): void
3219
3220Obtains 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).
3221
3222> **NOTE**<br>
3223> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getRssiValue](js-apis-bluetoothManager.md#getrssivaluedeprecated).
3224
3225**Required permissions**: ohos.permission.USE_BLUETOOTH
3226
3227**System capability**: SystemCapability.Communication.Bluetooth.Core
3228
3229**Parameters**
3230
3231| Name     | Type                         | Mandatory  | Description                            |
3232| -------- | --------------------------- | ---- | ------------------------------ |
3233| callback | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the RSSI, in dBm.|
3234
3235**Return value**
3236
3237No value is returned.
3238
3239**Example**
3240
3241```js
3242import { BusinessError } from '@ohos.base';
3243// callback
3244let gattClient : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
3245let ret : boolean = gattClient.connect();
3246gattClient.getRssiValue((err : BusinessError, data : number)=> {
3247    console.info('rssi err ' + JSON.stringify(err));
3248    console.info('rssi value' + JSON.stringify(data));
3249})
3250```
3251
3252
3253### getRssiValue<sup>(deprecated)</sup>
3254
3255getRssiValue(): Promise&lt;number&gt;
3256
3257Obtains 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).
3258
3259> **NOTE**<br>
3260> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getRssiValue](js-apis-bluetoothManager.md#getrssivaluedeprecated-1).
3261
3262**Required permissions**: ohos.permission.USE_BLUETOOTH
3263
3264**System capability**: SystemCapability.Communication.Bluetooth.Core
3265
3266**Return value**
3267
3268| Type                   | Description                               |
3269| --------------------- | --------------------------------- |
3270| Promise&lt;number&gt; | Promise used to return the RSSI, in dBm.|
3271
3272**Example**
3273
3274```js
3275// promise
3276let gattClient : bluetooth.GattClientDevice = bluetooth.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
3277gattClient.getRssiValue().then((data : number) => {
3278    console.info('rssi' + JSON.stringify(data));
3279})
3280```
3281
3282## ScanMode<sup>8+</sup><sup>(deprecated)</sup><a name="ScanMode"></a>
3283
3284Enumerates the scan modes.
3285
3286> **NOTE**<br>
3287> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanMode](js-apis-bluetoothManager.md#scanmodedeprecated).
3288
3289**System capability**: SystemCapability.Communication.Bluetooth.Core
3290
3291| Name                                      | Value | Description             |
3292| ---------------------------------------- | ---- | --------------- |
3293| SCAN_MODE_NONE                           | 0    | No scan mode.        |
3294| SCAN_MODE_CONNECTABLE                    | 1    | Connectable mode.       |
3295| SCAN_MODE_GENERAL_DISCOVERABLE           | 2    | General discoverable mode.   |
3296| SCAN_MODE_LIMITED_DISCOVERABLE           | 3    | Limited discoverable mode.   |
3297| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4    | General connectable and discoverable mode.|
3298| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5    | Limited connectable and discoverable mode.|
3299
3300## BondState<sup>8+</sup><sup>(deprecated)</sup><a name="BondState"></a>
3301
3302Enumerates the pairing states.
3303
3304> **NOTE**<br>
3305> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.BondState](js-apis-bluetoothManager.md#bondstatedeprecated).
3306
3307**System capability**: SystemCapability.Communication.Bluetooth.Core
3308
3309| Name                | Value | Description    |
3310| ------------------ | ---- | ------ |
3311| BOND_STATE_INVALID | 0    | Invalid pairing.|
3312| BOND_STATE_BONDING | 1    | Pairing. |
3313| BOND_STATE_BONDED  | 2    | Paired.  |
3314
3315
3316## SppOption<sup>8+</sup><sup>(deprecated)</sup><a name="SppOption"></a>
3317
3318Defines the SPP configuration parameters.
3319
3320> **NOTE**<br>
3321> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.SppOption](js-apis-bluetoothManager.md#sppoptiondeprecated).
3322
3323**System capability**: SystemCapability.Communication.Bluetooth.Core
3324
3325| Name    | Type               | Readable  | Writable  | Description         |
3326| ------ | ------------------- | ---- | ---- | ----------- |
3327| uuid   | string              | Yes   | Yes   | UUID of the SPP.|
3328| secure | boolean             | Yes   | Yes   | Whether it is a secure channel.   |
3329| type   | [SppType](#spptype) | Yes   | Yes   | Type of the SPP link.   |
3330
3331
3332## SppType<sup>8+</sup><sup>(deprecated)</sup><a name="SppType"></a>
3333
3334Enumerates the SPP link types.
3335
3336> **NOTE**<br>
3337> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.SppType](js-apis-bluetoothManager.md#spptypedeprecated).
3338
3339**System capability**: SystemCapability.Communication.Bluetooth.Core
3340
3341| Name        | Value | Description           |
3342| ---------- | ---- | ------------- |
3343| SPP_RFCOMM | 0    | Radio frequency communication (RFCOMM) link type.|
3344
3345
3346## GattService<sup>(deprecated)</sup>
3347
3348Defines the GATT service API parameters.
3349
3350> **NOTE**<br>
3351> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattService](js-apis-bluetoothManager.md#gattservicedeprecated).
3352
3353**System capability**: SystemCapability.Communication.Bluetooth.Core
3354
3355| Name             | Type                                    | Readable  | Writable  | Description                                      |
3356| --------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
3357| serviceUuid     | string                                   | Yes   | Yes   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3358| isPrimary       | boolean                                  | Yes   | Yes   | Whether the service is a primary service. The value **true** means a primary service.               |
3359| characteristics | Array&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes   | Yes   | List of characteristics of the service.                            |
3360| includeServices | Array&lt;[GattService](#gattservice)&gt; | Yes   | Yes   | Services on which the service depends.                            |
3361
3362
3363## BLECharacteristic<sup>(deprecated)</sup>
3364
3365Defines the characteristic API parameters.
3366
3367> **NOTE**<br>
3368> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLECharacteristic](js-apis-bluetoothManager.md#blecharacteristicdeprecated).
3369
3370**System capability**: SystemCapability.Communication.Bluetooth.Core
3371
3372| Name                 | Type                                    | Readable  | Writable  | Description                                      |
3373| ------------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
3374| serviceUuid         | string                                   | Yes   | Yes   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3375| characteristicUuid  | string                                   | Yes   | Yes   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
3376| characteristicValue | ArrayBuffer                              | Yes   | Yes   | Binary value of the characteristic.                              |
3377| descriptors         | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes   | Yes   | List of descriptors of the characteristic.                             |
3378
3379
3380## BLEDescriptor<sup>(deprecated)</sup>
3381
3382Defines the descriptor API parameters.
3383
3384> **NOTE**<br>
3385> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLEDescriptor](js-apis-bluetoothManager.md#bledescriptordeprecated).
3386
3387**System capability**: SystemCapability.Communication.Bluetooth.Core
3388
3389| Name                | Type       | Readable  | Writable  | Description                                      |
3390| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
3391| serviceUuid        | string      | Yes   | Yes   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3392| characteristicUuid | string      | Yes   | Yes   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
3393| descriptorUuid     | string      | Yes   | Yes   | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
3394| descriptorValue    | ArrayBuffer | Yes   | Yes   | Binary value of the descriptor.                             |
3395
3396
3397## NotifyCharacteristic<sup>(deprecated)</sup>
3398
3399Defines the parameters in the notifications sent when the server characteristic value changes.
3400
3401> **NOTE**<br>
3402> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.NotifyCharacteristic](js-apis-bluetoothManager.md#notifycharacteristicdeprecated).
3403
3404**System capability**: SystemCapability.Communication.Bluetooth.Core
3405
3406| Name                 | Type       | Readable  | Writable  | Description                                      |
3407| ------------------- | ----------- | ---- | ---- | ---------------------------------------- |
3408| serviceUuid         | string      | Yes   | Yes   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3409| characteristicUuid  | string      | Yes   | Yes   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
3410| characteristicValue | ArrayBuffer | Yes   | Yes   | Binary value of the characteristic.                              |
3411| 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.|
3412
3413
3414## CharacteristicReadReq<sup>(deprecated)</sup>
3415
3416Defines the parameters of the **CharacteristicReadReq** event received by the server.
3417
3418> **NOTE**<br>
3419> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.CharacteristicReadRequest](js-apis-bluetoothManager.md#characteristicreadrequestdeprecated).
3420
3421**System capability**: SystemCapability.Communication.Bluetooth.Core
3422
3423| Name                | Type  | Readable  | Writable  | Description                                      |
3424| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
3425| deviceId           | string | Yes   | No   | Address of the remote device that sends the **CharacteristicReadReq** event, for example, XX:XX:XX:XX:XX:XX.|
3426| transId            | number | Yes   | No   | Transmission ID of the read request. The response returned by the server must use the same transmission ID.      |
3427| 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.|
3428| characteristicUuid | string | Yes   | No   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
3429| serviceUuid        | string | Yes   | No   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3430
3431
3432## CharacteristicWriteReq<sup>(deprecated)</sup>
3433
3434Defines the parameters of the **CharacteristicWriteReq** event received by the server.
3435
3436> **NOTE**<br>
3437> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.CharacteristicWriteRequest](js-apis-bluetoothManager.md#characteristicwriterequestdeprecated).
3438
3439**System capability**: SystemCapability.Communication.Bluetooth.Core
3440
3441| Name                | Type  | Readable  | Writable  | Description                                      |
3442| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
3443| deviceId           | string | Yes   | No   | Address of the remote device that sends the **CharacteristicWriteReq** event, for example, XX:XX:XX:XX:XX:XX.|
3444| transId            | number | Yes   | No   | Transmission ID of the write request. The response returned by the server must use the same transmission ID.      |
3445| 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.|
3446| descriptorUuid     | string | Yes   | No   | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
3447| characteristicUuid | string | Yes   | No   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
3448| serviceUuid        | string | Yes   | No   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3449
3450
3451## DescriptorReadReq<sup>(deprecated)</sup>
3452
3453Defines the parameters of the **DescriptorReadReq** event received by the server.
3454
3455> **NOTE**<br>
3456> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.DescriptorReadRequest](js-apis-bluetoothManager.md#descriptorreadrequestdeprecated).
3457
3458**System capability**: SystemCapability.Communication.Bluetooth.Core
3459
3460| Name                | Type  | Readable  | Writable  | Description                                      |
3461| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
3462| deviceId           | string | Yes   | No   | Address of the remote device that sends a **DescriptorReadReq** event, for example, XX:XX:XX:XX:XX:XX.|
3463| transId            | number | Yes   | No   | Transmission ID of the read request. The response returned by the server must use the same transmission ID.      |
3464| 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.|
3465| descriptorUuid     | string | Yes   | No   | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
3466| characteristicUuid | string | Yes   | No   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
3467| serviceUuid        | string | Yes   | No   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3468
3469
3470## DescriptorWriteReq<sup>(deprecated)</sup>
3471
3472Defines the parameters of the **DescriptorWriteReq** event received by the server.
3473
3474> **NOTE**<br>
3475> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.DescriptorWriteRequest](js-apis-bluetoothManager.md#descriptorwriterequestdeprecated).
3476
3477**System capability**: SystemCapability.Communication.Bluetooth.Core
3478
3479| Name                | Type       | Readable  | Writable  | Description                                      |
3480| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
3481| deviceId           | string      | Yes   | No   | Address of the remote device that sends a **DescriptorWriteReq** event, for example, XX:XX:XX:XX:XX:XX.|
3482| transId            | number      | Yes   | No   | Transmission ID of the write request. The response returned by the server must use the same transmission ID.      |
3483| 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.|
3484| isPrep             | boolean     | Yes   | No   | Whether the write request is executed immediately.                            |
3485| needRsp            | boolean     | Yes   | No   | Whether to send a response to the GATT client.                      |
3486| value              | ArrayBuffer | Yes   | No   | Binary value of the descriptor to write.                          |
3487| descriptorUuid     | string      | Yes   | No   | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
3488| characteristicUuid | string      | Yes   | No   | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
3489| serviceUuid        | string      | Yes   | No   | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3490
3491
3492## ServerResponse<sup>(deprecated)</sup>
3493
3494Defines the parameters of the server's response to the GATT client's read/write request.
3495
3496> **NOTE**<br>
3497> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ServerResponse](js-apis-bluetoothManager.md#serverresponsedeprecated).
3498
3499**System capability**: SystemCapability.Communication.Bluetooth.Core
3500
3501| Name      | Type       | Readable  | Writable  | Description                                    |
3502| -------- | ----------- | ---- | ---- | -------------------------------------- |
3503| deviceId | string      | Yes   | No   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.      |
3504| 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.       |
3505| status   | number      | Yes   | No   | Response state. Set this parameter to **0**, which indicates a normal response.                  |
3506| offset   | number      | Yes   | No   | Start read/write position. The value must be the same as the offset carried in the read/write request.|
3507| value    | ArrayBuffer | Yes   | No   | Binary data in the response.                         |
3508
3509
3510## BLEConnectChangedState<sup>(deprecated)</sup>
3511
3512Defines the parameters of **BLEConnectChangedState**.
3513
3514> **NOTE**<br>
3515> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLEConnectChangedState](js-apis-bluetoothManager.md#bleconnectchangedstatedeprecated).
3516
3517**System capability**: SystemCapability.Communication.Bluetooth.Core
3518
3519| Name    | Type                                         | Readable| Writable| Description                                         |
3520| -------- | ------------------------------------------------- | ---- | ---- | --------------------------------------------- |
3521| deviceId | string                                            | Yes  | No  | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
3522| state    | [ProfileConnectionState](#profileconnectionstate) | Yes  | Yes  | BLE connection state.                      |
3523
3524
3525## ProfileConnectionState<sup>(deprecated)</sup>
3526
3527Enumerates the profile connection states.
3528
3529> **NOTE**<br>
3530> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ProfileConnectionState](js-apis-bluetoothManager.md#profileconnectionstatedeprecated).
3531
3532**System capability**: SystemCapability.Communication.Bluetooth.Core
3533
3534| Name                 | Value | Description            |
3535| ------------------- | ---- | -------------- |
3536| STATE_DISCONNECTED  | 0    | Disconnected. |
3537| STATE_CONNECTING    | 1    | Connecting.|
3538| STATE_CONNECTED     | 2    | Connected. |
3539| STATE_DISCONNECTING | 3    | Disconnecting.|
3540
3541
3542## ScanFilter<sup>(deprecated)</sup>
3543
3544Defines the scan filter parameters.
3545
3546> **NOTE**<br>
3547> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanFilter](js-apis-bluetoothManager.md#scanfilterdeprecated).
3548
3549**System capability**: SystemCapability.Communication.Bluetooth.Core
3550
3551| Name                                    | Type   | Readable| Writable| Description                                                        |
3552| ---------------------------------------- | ----------- | ---- | ---- | ------------------------------------------------------------ |
3553| deviceId                                 | string      | Yes  | Yes  | Address of the BLE device to filter, for example, XX:XX:XX:XX:XX:XX.          |
3554| name                                     | string      | Yes  | Yes  | Name of the BLE device to filter.                                       |
3555| serviceUuid                              | string      | Yes  | Yes  | Service UUID of the device to filter, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
3556
3557
3558## ScanOptions<sup>(deprecated)</sup>
3559
3560Defines the scan configuration parameters.
3561
3562> **NOTE**<br>
3563> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanOptions](js-apis-bluetoothManager.md#scanoptionsdeprecated).
3564
3565**System capability**: SystemCapability.Communication.Bluetooth.Core
3566
3567| Name       | Type                   | Readable  | Writable  | Description                                    |
3568| --------- | ----------------------- | ---- | ---- | -------------------------------------- |
3569| interval  | number                  | Yes   | Yes   | Delay in reporting the scan result. The default value is **0**.                   |
3570| dutyMode  | [ScanDuty](#scanduty)   | Yes   | Yes   | Scan duty. The default value is **SCAN_MODE_LOW_POWER**.       |
3571| matchMode | [MatchMode](#matchmode) | Yes   | Yes   | Hardware filtering match mode. The default value is **MATCH_MODE_AGGRESSIVE**.|
3572
3573
3574## ScanDuty<sup>(deprecated)</sup>
3575
3576Enumerates the scan duty options.
3577
3578> **NOTE**<br>
3579> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanDuty](js-apis-bluetoothManager.md#scandutydeprecated).
3580
3581**System capability**: SystemCapability.Communication.Bluetooth.Core
3582
3583| Name                   | Value | Description          |
3584| --------------------- | ---- | ------------ |
3585| SCAN_MODE_LOW_POWER   | 0    | Low-power mode, which is the default value.|
3586| SCAN_MODE_BALANCED    | 1    | Balanced mode.     |
3587| SCAN_MODE_LOW_LATENCY | 2    | Low-latency mode.    |
3588
3589
3590## MatchMode<sup>(deprecated)</sup>
3591
3592Enumerates the hardware match modes of BLE scan filters.
3593
3594> **NOTE**<br>
3595> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.MatchMode](js-apis-bluetoothManager.md#matchmodedeprecated).
3596
3597**System capability**: SystemCapability.Communication.Bluetooth.Core
3598
3599| Name                   | Value | Description                                      |
3600| --------------------- | ---- | ---------------------------------------- |
3601| 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.|
3602| MATCH_MODE_STICKY     | 2    | Hardware reports the scan result with a higher threshold of signal strength and sightings.      |
3603
3604
3605## ScanResult<sup>(deprecated)</sup>
3606
3607Defines the scan result.
3608
3609> **NOTE**<br>
3610> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanResult](js-apis-bluetoothManager.md#scanresultdeprecated).
3611
3612**System capability**: SystemCapability.Communication.Bluetooth.Core
3613
3614| Name      | Type       | Readable  | Writable  | Description                                |
3615| -------- | ----------- | ---- | ---- | ---------------------------------- |
3616| deviceId | string      | Yes   | No   | Address of the scanned device, for example, XX:XX:XX:XX:XX:XX.|
3617| rssi     | number      | Yes   | No   | RSSI of the device.                   |
3618| data     | ArrayBuffer | Yes   | No   | Advertisement packets sent by the device.                   |
3619
3620
3621## BluetoothState<sup>(deprecated)</sup>
3622
3623Enumerates the Bluetooth states.
3624
3625> **NOTE**<br>
3626> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BluetoothState](js-apis-bluetoothManager.md#bluetoothstatedeprecated).
3627
3628**System capability**: SystemCapability.Communication.Bluetooth.Core
3629
3630| Name                   | Value | Description                |
3631| --------------------- | ---- | ------------------ |
3632| STATE_OFF             | 0    | Bluetooth is turned off.          |
3633| STATE_TURNING_ON      | 1    | Bluetooth is being turned on.         |
3634| STATE_ON              | 2    | Bluetooth is turned on.          |
3635| STATE_TURNING_OFF     | 3    | Bluetooth is being turned off.         |
3636| STATE_BLE_TURNING_ON  | 4    | The LE-only mode is being turned on for Bluetooth.|
3637| STATE_BLE_ON          | 5    | Bluetooth is in LE-only mode. |
3638| STATE_BLE_TURNING_OFF | 6    | The LE-only mode is being turned off for Bluetooth.|
3639
3640
3641## AdvertiseSetting<sup>(deprecated)</sup>
3642
3643Defines the BLE advertising parameters.
3644
3645> **NOTE**<br>
3646> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.AdvertiseSetting](js-apis-bluetoothManager.md#advertisesettingdeprecated).
3647
3648**System capability**: SystemCapability.Communication.Bluetooth.Core
3649
3650| Name         | Type   | Readable  | Writable  | Description                                      |
3651| ----------- | ------- | ---- | ---- | ---------------------------------------- |
3652| 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).|
3653| txPower     | number  | Yes   | Yes   | Transmit power, in dBm. The value range is -127 to 1. The default value is **-7**.  |
3654| connectable | boolean | Yes   | Yes   | Whether the advertisement is connectable. The default value is **true**.                  |
3655
3656
3657## AdvertiseData<sup>(deprecated)</sup>
3658
3659Defines the content of a BLE advertisement packet.
3660
3661> **NOTE**<br>
3662> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.AdvertiseData](js-apis-bluetoothManager.md#advertisedatadeprecated).
3663
3664**System capability**: SystemCapability.Communication.Bluetooth.Core
3665
3666| Name             | Type                                    | Readable  | Writable  | Description                         |
3667| --------------- | ---------------------------------------- | ---- | ---- | --------------------------- |
3668| serviceUuids    | Array&lt;string&gt;                      | Yes   | Yes   | List of service UUIDs to broadcast.|
3669| manufactureData | Array&lt;[ManufactureData](#manufacturedata)&gt; | Yes   | Yes   | List of manufacturers to broadcast.          |
3670| serviceData     | Array&lt;[ServiceData](#servicedata)&gt; | Yes   | Yes   | List of service data to broadcast.              |
3671
3672
3673## ManufactureData<sup>(deprecated)</sup>
3674
3675Defines the content of a BLE advertisement packet.
3676
3677> **NOTE**<br>
3678> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ManufactureData](js-apis-bluetoothManager.md#manufacturedatadeprecated).
3679
3680**System capability**: SystemCapability.Communication.Bluetooth.Core
3681
3682| Name              | Type               | Readable  | Writable  | Description                |
3683| ---------------- | ------------------- | ---- | ---- | ------------------ |
3684| manufactureId    | number  | Yes   | Yes   | Manufacturer ID allocated by the Bluetooth SIG.|
3685| manufactureValue | ArrayBuffer         | Yes   | Yes   | Manufacturer data.    |
3686
3687
3688## ServiceData<sup>(deprecated)</sup>
3689
3690Defines the service data contained in an advertisement packet.
3691
3692> **NOTE**<br>
3693> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ServiceData](js-apis-bluetoothManager.md#servicedatadeprecated).
3694
3695**System capability**: SystemCapability.Communication.Bluetooth.Core
3696
3697| Name          | Type       | Readable  | Writable  | Description        |
3698| ------------ | ----------- | ---- | ---- | ---------- |
3699| serviceUuid  | string      | Yes   | Yes   | Service UUID.|
3700| serviceValue | ArrayBuffer | Yes   | Yes   | Service data.   |
3701
3702
3703## PinRequiredParam<sup>8+</sup><sup>(deprecated)</sup><a name="PinRequiredParam"></a>
3704
3705Defines the pairing request parameters.
3706
3707> **NOTE**<br>
3708> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.PinRequiredParam](js-apis-bluetoothManager.md#pinrequiredparamdeprecated).
3709
3710**System capability**: SystemCapability.Communication.Bluetooth.Core
3711
3712| Name      | Type  | Readable  | Writable  | Description         |
3713| -------- | ------ | ---- | ---- | ----------- |
3714| deviceId | string | Yes   | No   | ID of the device to pair.|
3715| pinCode  | string | Yes   | No   | Key for the device pairing.  |
3716
3717
3718## BondStateParam<sup>8+</sup><sup>(deprecated)</sup><a name="BondStateParam"></a>
3719
3720Defines the pairing state parameters.
3721
3722> **NOTE**<br>
3723> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.BondStateParam](js-apis-bluetoothManager.md#bondstateparamdeprecated).
3724
3725**System capability**: SystemCapability.Communication.Bluetooth.Core
3726
3727| Name      | Type  | Readable  | Writable  | Description         |
3728| -------- | ------ | ---- | ---- | ----------- |
3729| deviceId | string      | Yes   | No   | ID of the device to pair.|
3730| state    | BondState   | Yes   | No   | State of the device.|
3731
3732
3733## StateChangeParam<sup>8+</sup><sup>(deprecated)</sup><a name="StateChangeParam"></a>
3734
3735Defines the profile state change parameters.
3736
3737> **NOTE**<br>
3738> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.StateChangeParam](js-apis-bluetoothManager.md#statechangeparamdeprecated).
3739
3740**System capability**: SystemCapability.Communication.Bluetooth.Core
3741
3742| Name    | Type                                         | Readable| Writable| Description                           |
3743| -------- | ------------------------------------------------- | ---- | ---- | ------------------------------- |
3744| deviceId | string                                            | Yes  | No  | Address of a Bluetooth device.             |
3745| state    | [ProfileConnectionState](#profileconnectionstate) | Yes  | No  | Profile connection state of the device.|
3746
3747
3748## DeviceClass<sup>8+</sup><sup>(deprecated)</sup><a name="DeviceClass"></a>
3749
3750Defines the class of a Bluetooth device.
3751
3752> **NOTE**<br>
3753> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.DeviceClass](js-apis-bluetoothManager.md#deviceclassdeprecated).
3754
3755**System capability**: SystemCapability.Communication.Bluetooth.Core
3756
3757| Name             | Type                               | Readable  | Writable  | Description              |
3758| --------------- | ----------------------------------- | ---- | ---- | ---------------- |
3759| majorClass      | [MajorClass](#majorclass)           | Yes   | No   | Major classes of Bluetooth devices.  |
3760| majorMinorClass | [MajorMinorClass](#majorminorclass) | Yes   | No   | Major and minor classes of Bluetooth devices.|
3761| classOfDevice   | number                              | Yes   | No   | Class of the device.         |
3762
3763
3764
3765## MajorClass<sup>8+</sup><sup>(deprecated)</sup><a name="MajorClass"></a>
3766
3767Enumerates the major classes of Bluetooth devices.
3768
3769> **NOTE**<br>
3770> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.MajorClass](js-apis-bluetoothManager.md#majorclassdeprecated).
3771
3772**System capability**: SystemCapability.Communication.Bluetooth.Core
3773
3774| Name                 | Value   | Description        |
3775| ------------------- | ------ | ---------- |
3776| MAJOR_MISC          | 0x0000 | Miscellaneous device.   |
3777| MAJOR_COMPUTER      | 0x0100 | Computer.  |
3778| MAJOR_PHONE         | 0x0200 | Mobile phone.   |
3779| MAJOR_NETWORKING    | 0x0300 | Network device.   |
3780| MAJOR_AUDIO_VIDEO   | 0x0400 | Audio or video device.|
3781| MAJOR_PERIPHERAL    | 0x0500 | Peripheral device.   |
3782| MAJOR_IMAGING       | 0x0600 | Imaging device.   |
3783| MAJOR_WEARABLE      | 0x0700 | Wearable device.  |
3784| MAJOR_TOY           | 0x0800 | Toy.   |
3785| MAJOR_HEALTH        | 0x0900 | Health device.   |
3786| MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device.  |
3787
3788
3789## MajorMinorClass<sup>8+</sup><sup>(deprecated)</sup><a name="MajorMinorClass"></a>
3790
3791Enumerates the major and minor classes of Bluetooth devices.
3792
3793> **NOTE**<br>
3794> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.MajorMinorClass](js-apis-bluetoothManager.md#majorminorclassdeprecated).
3795
3796**System capability**: SystemCapability.Communication.Bluetooth.Core
3797
3798| Name                                      | Value   | Description             |
3799| ---------------------------------------- | ------ | --------------- |
3800| COMPUTER_UNCATEGORIZED                   | 0x0100 | Unclassified computer.    |
3801| COMPUTER_DESKTOP                         | 0x0104 | Desktop computer.     |
3802| COMPUTER_SERVER                          | 0x0108 | Server.       |
3803| COMPUTER_LAPTOP                          | 0x010C | Laptop.    |
3804| COMPUTER_HANDHELD_PC_PDA                 | 0x0110 | Hand-held computer.    |
3805| COMPUTER_PALM_SIZE_PC_PDA                | 0x0114 | Palmtop computer.      |
3806| COMPUTER_WEARABLE                        | 0x0118 | Wearable computer.    |
3807| COMPUTER_TABLET                          | 0x011C | Tablet.      |
3808| PHONE_UNCATEGORIZED                      | 0x0200 | Unclassified mobile phone.     |
3809| PHONE_CELLULAR                           | 0x0204 | Portable phone.     |
3810| PHONE_CORDLESS                           | 0x0208 | Cordless phone.      |
3811| PHONE_SMART                              | 0x020C | Smartphone.      |
3812| PHONE_MODEM_OR_GATEWAY                   | 0x0210 | Modem or gateway phone.|
3813| PHONE_ISDN                               | 0x0214 | ISDN phone.    |
3814| NETWORK_FULLY_AVAILABLE                  | 0x0300 | Device with network fully available.    |
3815| NETWORK_1_TO_17_UTILIZED                 | 0x0320 | Device used on network 1 to 17.  |
3816| NETWORK_17_TO_33_UTILIZED                | 0x0340 | Device used on network 17 to 33. |
3817| NETWORK_33_TO_50_UTILIZED                | 0x0360 | Device used on network 33 to 50. |
3818| NETWORK_60_TO_67_UTILIZED                | 0x0380 | Device used on network 60 to 67. |
3819| NETWORK_67_TO_83_UTILIZED                | 0x03A0 | Device used on network 67 to 83. |
3820| NETWORK_83_TO_99_UTILIZED                | 0x03C0 | Device used on network 83 to 99. |
3821| NETWORK_NO_SERVICE                       | 0x03E0 | Device without network service     |
3822| AUDIO_VIDEO_UNCATEGORIZED                | 0x0400 | Unclassified audio or video device.   |
3823| AUDIO_VIDEO_WEARABLE_HEADSET             | 0x0404 | Wearable audio or video headset.  |
3824| AUDIO_VIDEO_HANDSFREE                    | 0x0408 | Hands-free audio or video device.    |
3825| AUDIO_VIDEO_MICROPHONE                   | 0x0410 | Audio or video microphone.   |
3826| AUDIO_VIDEO_LOUDSPEAKER                  | 0x0414 | Audio or video loudspeaker.   |
3827| AUDIO_VIDEO_HEADPHONES                   | 0x0418 | Audio or video headphones.   |
3828| AUDIO_VIDEO_PORTABLE_AUDIO               | 0x041C | Portable audio or video device.   |
3829| AUDIO_VIDEO_CAR_AUDIO                    | 0x0420 | In-vehicle audio or video device.    |
3830| AUDIO_VIDEO_SET_TOP_BOX                  | 0x0424 | Audio or video STB device.   |
3831| AUDIO_VIDEO_HIFI_AUDIO                   | 0x0428 | High-fidelity speaker device.     |
3832| AUDIO_VIDEO_VCR                          | 0x042C | Video cassette recording (VCR) device.   |
3833| AUDIO_VIDEO_VIDEO_CAMERA                 | 0x0430 | Camera.   |
3834| AUDIO_VIDEO_CAMCORDER                    | 0x0434 | Camcorder   |
3835| AUDIO_VIDEO_VIDEO_MONITOR                | 0x0438 | Audio or video monitor.   |
3836| AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER | 0x043C | Video display or loudspeaker. |
3837| AUDIO_VIDEO_VIDEO_CONFERENCING           | 0x0440 | Video conferencing device.    |
3838| AUDIO_VIDEO_VIDEO_GAMING_TOY             | 0x0448 | Audio or video gaming toy.  |
3839| PERIPHERAL_NON_KEYBOARD_NON_POINTING     | 0x0500 | Non-keyboard or non-pointing peripheral device.  |
3840| PERIPHERAL_KEYBOARD                      | 0x0540 | Keyboard device.      |
3841| PERIPHERAL_POINTING_DEVICE               | 0x0580 | Pointing peripheral device.    |
3842| PERIPHERAL_KEYBOARD_POINTING             | 0x05C0 | Keyboard pointing device.    |
3843| PERIPHERAL_UNCATEGORIZED                 | 0x0500 | Unclassified peripheral device.     |
3844| PERIPHERAL_JOYSTICK                      | 0x0504 | Peripheral joystick.     |
3845| PERIPHERAL_GAMEPAD                       | 0x0508 | Peripheral game pad     |
3846| PERIPHERAL_REMOTE_CONTROL                | 0x05C0 | Peripheral remote control device    |
3847| PERIPHERAL_SENSING_DEVICE                | 0x0510 | Peripheral sensing device.    |
3848| PERIPHERAL_DIGITIZER_TABLET              | 0x0514 | Peripheral digitizer tablet.|
3849| PERIPHERAL_CARD_READER                   | 0x0518 | Peripheral card reader.     |
3850| PERIPHERAL_DIGITAL_PEN                   | 0x051C | Peripheral digital pen.     |
3851| PERIPHERAL_SCANNER_RFID                  | 0x0520 | Peripheral RFID scanner. |
3852| PERIPHERAL_GESTURAL_INPUT                | 0x0522 | Gesture input device.    |
3853| IMAGING_UNCATEGORIZED                    | 0x0600 | Unclassified imaging device.    |
3854| IMAGING_DISPLAY                          | 0x0610 | Imaging display device.      |
3855| IMAGING_CAMERA                           | 0x0620 | Imaging camera device.     |
3856| IMAGING_SCANNER                          | 0x0640 | Imaging scanner.     |
3857| IMAGING_PRINTER                          | 0x0680 | Imaging printer.     |
3858| WEARABLE_UNCATEGORIZED                   | 0x0700 | Unclassified wearable device.   |
3859| WEARABLE_WRIST_WATCH                     | 0x0704 | Smart watch.     |
3860| WEARABLE_PAGER                           | 0x0708 | Wearable pager.    |
3861| WEARABLE_JACKET                          | 0x070C | Smart jacket.     |
3862| WEARABLE_HELMET                          | 0x0710 | Wearable helmet.     |
3863| WEARABLE_GLASSES                         | 0x0714 | Wearable glasses.     |
3864| TOY_UNCATEGORIZED                        | 0x0800 | Unclassified toy.    |
3865| TOY_ROBOT                                | 0x0804 | Toy robot.     |
3866| TOY_VEHICLE                              | 0x0808 | Toy vehicle.       |
3867| TOY_DOLL_ACTION_FIGURE                   | 0x080C | Humanoid toy doll.    |
3868| TOY_CONTROLLER                           | 0x0810 | Toy controller.     |
3869| TOY_GAME                                 | 0x0814 | Toy gaming device.      |
3870| HEALTH_UNCATEGORIZED                     | 0x0900 | Unclassified health devices.     |
3871| HEALTH_BLOOD_PRESSURE                    | 0x0904 | Blood pressure device.      |
3872| HEALTH_THERMOMETER                       | 0x0908 | Thermometer     |
3873| HEALTH_WEIGHING                          | 0x090C | Body scale.      |
3874| HEALTH_GLUCOSE                           | 0x0910 | Blood glucose monitor.     |
3875| HEALTH_PULSE_OXIMETER                    | 0x0914 | Pulse oximeter.   |
3876| HEALTH_PULSE_RATE                        | 0x0918 | Heart rate monitor.     |
3877| HEALTH_DATA_DISPLAY                      | 0x091C | Health data display.    |
3878| HEALTH_STEP_COUNTER                      | 0x0920 | Step counter.   |
3879| HEALTH_BODY_COMPOSITION_ANALYZER         | 0x0924 | Body composition analyzer. |
3880| HEALTH_PEAK_FLOW_MOITOR                  | 0x0928 | Hygrometer.     |
3881| HEALTH_MEDICATION_MONITOR                | 0x092C | Medication monitor.   |
3882| HEALTH_KNEE_PROSTHESIS                   | 0x0930 | Prosthetic knee.    |
3883| HEALTH_ANKLE_PROSTHESIS                  | 0x0934 | Prosthetic ankle.    |
3884| HEALTH_GENERIC_HEALTH_MANAGER            | 0x0938 | Generic health management device.    |
3885| HEALTH_PERSONAL_MOBILITY_DEVICE          | 0x093C | Personal mobility device.    |
3886
3887
3888## PlayingState<sup>8+</sup><sup>(deprecated)</sup><a name="PlayingState"></a>
3889
3890Enumerates the A2DP playing states.
3891
3892> **NOTE**<br>
3893> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.PlayingState](js-apis-bluetoothManager.md#playingstatedeprecated).
3894
3895**System capability**: SystemCapability.Communication.Bluetooth.Core
3896
3897| Name               | Value   | Description     |
3898| ----------------- | ------ | ------- |
3899| STATE_NOT_PLAYING | 0x0000 | Not playing. |
3900| STATE_PLAYING     | 0x0001 | Playing.|
3901
3902
3903## ProfileId<sup>8+</sup><sup>(deprecated)</sup><a name="ProfileId"></a>
3904
3905Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOST** and **PROFILE_PAN_NETWORK**.
3906
3907> **NOTE**<br>
3908> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.ProfileId](js-apis-bluetoothManager.md#profileiddeprecated).
3909
3910**System capability**: SystemCapability.Communication.Bluetooth.Core
3911
3912| Name                              | Value   | Description             |
3913| -------------------------------- | ------ | --------------- |
3914| PROFILE_A2DP_SOURCE              | 1 | A2DP profile.|
3915| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | HFP profile. |
3916