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