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