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