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