1# @ohos.bluetooth.connection (Bluetooth Connection Module) 2 3The **connection** module provides APIs for operating and managing Bluetooth. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9 10 11## Modules to Import 12 13```js 14import { connection } from '@kit.ConnectivityKit'; 15``` 16 17 18## ProfileConnectionState 19 20type ProfileConnectionState = constant.ProfileConnectionState 21 22Defines the profile connection status of the Bluetooth device. 23 24**System capability**: SystemCapability.Communication.Bluetooth.Core 25 26| Type | Description | 27| ------------------- | ------------------- | 28| [constant.ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate) | Profile connection status of the Bluetooth device.| 29 30 31## ProfileId 32 33type ProfileId = constant.ProfileId 34 35Enumerates profiles of the Bluetooth device. 36 37**System capability**: SystemCapability.Communication.Bluetooth.Core 38 39| Type | Description | 40| ------------------- | ------------------- | 41| [constant.ProfileId](js-apis-bluetooth-constant.md#profileid) | Profile of the Bluetooth device.| 42 43 44## ProfileUuids<sup>12+</sup> 45 46type ProfileUuids = constant.ProfileUuids 47 48Defines the UUID of a profile. 49 50**System capability**: SystemCapability.Communication.Bluetooth.Core 51 52| Type | Description | 53| ------------------- | ------------------- | 54| [constant.ProfileUuids](js-apis-bluetooth-constant.md#profileuuids) | UUID of the profile.| 55 56 57## MajorClass 58 59type MajorClass = constant.MajorClass 60 61Main class of the Bluetooth device. 62 63**System capability**: SystemCapability.Communication.Bluetooth.Core 64 65| Type | Description | 66| ------------------- | ------------------- | 67| [constant.MajorClass](js-apis-bluetooth-constant.md#majorclass) | Main class of the Bluetooth device.| 68 69 70## MajorMinorClass 71 72type MajorMinorClass = constant.MajorMinorClass 73 74Major and minor classes of the Bluetooth device. 75 76**System capability**: SystemCapability.Communication.Bluetooth.Core 77 78| Type | Description | 79| ------------------- | ------------------- | 80| [constant.MajorMinorClass](js-apis-bluetooth-constant.md#majorminorclass) | Major and minor classes of the Bluetooth device.| 81 82 83## connection.pairDevice 84 85pairDevice(deviceId: string, callback: AsyncCallback<void>): void 86 87Pairs a Bluetooth device. This API uses an asynchronous callback to return the result. 88 89**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 90 91**Atomic service API**: This API can be used in atomic services since API version 12. 92 93**System capability**: SystemCapability.Communication.Bluetooth.Core 94 95**Parameters** 96 97| Name | Type | Mandatory | Description | 98| -------- | ------ | ---- | ----------------------------------- | 99| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.| 100| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the pairing is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 101 102**Error codes** 103 104For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 105 106| ID| Error Message| 107| -------- | ---------------------------- | 108|201 | Permission denied. | 109|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 110|801 | Capability not supported. | 111|2900001 | Service stopped. | 112|2900003 | Bluetooth disabled. | 113|2900099 | Operation failed. | 114 115**Example** 116 117```js 118import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 119// callback 120try { 121 connection.pairDevice('11:22:33:44:55:66', (err: BusinessError) => { 122 console.info('pairDevice, device name err:' + JSON.stringify(err)); 123 }); 124} catch (err) { 125 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 126} 127 128``` 129 130 131## connection.pairDevice 132 133pairDevice(deviceId: string): Promise<void> 134 135Pairs a Bluetooth device. This API uses a promise to return the result. 136 137**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 138 139**Atomic service API**: This API can be used in atomic services since API version 12. 140 141**System capability**: SystemCapability.Communication.Bluetooth.Core 142 143**Parameters** 144 145| Name | Type | Mandatory | Description | 146| -------- | ------ | ---- | ----------------------------------- | 147| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.| 148 149**Return value** 150 151| Type | Description | 152| ------------------- | ------------- | 153| Promise<void> | Promise used to return the result.| 154 155**Error codes** 156 157For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 158 159| ID| Error Message| 160| -------- | ---------------------------- | 161|201 | Permission denied. | 162|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 163|801 | Capability not supported. | 164|2900001 | Service stopped. | 165|2900003 | Bluetooth disabled. | 166|2900099 | Operation failed. | 167 168**Example** 169 170```js 171import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 172// promise 173try { 174 connection.pairDevice('11:22:33:44:55:66').then(() => { 175 console.info('pairDevice'); 176 }, (error: BusinessError) => { 177 console.info('pairDevice: errCode:' + error.code + ',errMessage' + error.message); 178 }) 179 180} catch (err) { 181 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 182} 183``` 184 185 186## connection.getRemoteDeviceName 187 188getRemoteDeviceName(deviceId: string): string 189 190Obtains the name of a remote Bluetooth device. 191 192**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 193 194**Atomic service API**: This API can be used in atomic services since API version 12. 195 196**System capability**: SystemCapability.Communication.Bluetooth.Core 197 198**Parameters** 199 200| Name | Type | Mandatory | Description | 201| -------- | ------ | ---- | --------------------------------- | 202| deviceId | string | Yes | Address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 203 204**Return value** 205 206| Type | Description | 207| ------ | ------------- | 208| string | Device name (a string) obtained.| 209 210**Error codes** 211 212For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 213 214| ID| Error Message| 215| -------- | ---------------------------- | 216|201 | Permission denied. | 217|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 218|801 | Capability not supported. | 219|2900001 | Service stopped. | 220|2900003 | Bluetooth disabled. | 221|2900099 | Operation failed. | 222 223**Example** 224 225```js 226import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 227try { 228 let remoteDeviceName: string = connection.getRemoteDeviceName('XX:XX:XX:XX:XX:XX'); 229} catch (err) { 230 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 231} 232``` 233 234 235## connection.getRemoteDeviceName<sup>16+</sup> 236 237getRemoteDeviceName(deviceId: string, alias?: boolean): string 238 239Obtains the name of the peer device. The **alias** parameter is optional. 240- If the **alias** parameter is specified, the application determines whether to obtain the alias of the peer device. 241- If the **alias** parameter is not specified, the alias of the peer device is returned by default. 242 243**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 244 245**Atomic service API**: This API can be used in atomic services since API version 16. 246 247**System capability**: SystemCapability.Communication.Bluetooth.Core 248 249**Parameters** 250 251| Name | Type | Mandatory | Description | 252| -------- | ------ | ---- | --------------------------------- | 253| deviceId | string | Yes | Address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 254| alias | boolean | No | Whether to obtain the alias of the peer device. The value **true** means to obtain the alias, and the value **false** means the opposite.| 255 256**Return value** 257 258| Type | Description | 259| ------ | ------------- | 260| string | Device name (a string) obtained.| 261 262**Error codes** 263 264For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 265 266| ID| Error Message| 267| -------- | ---------------------------- | 268|201 | Permission denied. | 269|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 270|801 | Capability not supported. | 271|2900001 | Service stopped. | 272|2900003 | Bluetooth disabled. | 273|2900099 | Failed to obtain the name or alias of the peer Bluetooth device. | 274 275**Example** 276 277```js 278import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 279try { 280 let remoteDeviceName: string = connection.getRemoteDeviceName('XX:XX:XX:XX:XX:XX', true); 281} catch (err) { 282 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 283} 284``` 285 286 287## connection.getRemoteDeviceClass 288 289getRemoteDeviceClass(deviceId: string): DeviceClass 290 291Obtains the class of a remote Bluetooth device. Since API version 18, the **ohos.permission.ACCESS_BLUETOOTH** permission is no longer verified. 292 293**System capability**: SystemCapability.Communication.Bluetooth.Core 294 295**Parameters** 296 297| Name | Type | Mandatory | Description | 298| -------- | ------ | ---- | --------------------------------- | 299| deviceId | string | Yes | Address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 300 301**Return value** 302 303| Type | Description | 304| --------------------------- | -------- | 305| [DeviceClass](#deviceclass) | Class of the peer device obtained.| 306 307**Error codes** 308 309For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 310 311| ID| Error Message| 312| -------- | ---------------------------- | 313|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 314|801 | Capability not supported. | 315|2900001 | Service stopped. | 316|2900003 | Bluetooth disabled. | 317|2900099 | Operation failed. | 318 319**Example** 320 321```js 322import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 323try { 324 let remoteDeviceClass: connection.DeviceClass = connection.getRemoteDeviceClass('XX:XX:XX:XX:XX:XX'); 325} catch (err) { 326 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 327} 328``` 329 330 331## connection.getRemoteProfileUuids<sup>12+</sup> 332 333getRemoteProfileUuids(deviceId: string, callback: AsyncCallback<Array<ProfileUuids>>): void 334 335Obtains the profile UUIDs of a remote Bluetooth device. This API uses an asynchronous callback to return the result. 336 337**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 338 339**System capability**: SystemCapability.Communication.Bluetooth.Core 340 341**Parameters** 342 343| Name | Type | Mandatory | Description | 344| -------- | ------ | ---- | ----------------------------------- | 345| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.| 346| callback | AsyncCallback<Array<[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids12)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 347 348**Error codes** 349 350For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 351 352| ID| Error Message| 353| -------- | ---------------------------- | 354|201 | Permission denied. | 355|401 | Invalid parameter. | 356|801 | Capability not supported. | 357|2900001 | Service stopped. | 358|2900003 | Bluetooth disabled. | 359|2900099 | Operation failed. | 360 361**Example** 362 363```js 364import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 365try { 366 connection.getRemoteProfileUuids('XX:XX:XX:XX:XX:XX', (err: BusinessError, data: Array<connection.ProfileUuids>) => { 367 console.info('getRemoteProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data)); 368 }); 369} catch (err) { 370 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 371} 372 373``` 374 375 376## connection.getRemoteProfileUuids<sup>12+</sup> 377 378getRemoteProfileUuids(deviceId: string): Promise<Array<ProfileUuids>> 379 380Obtains the profile UUIDs of a remote Bluetooth device. This API uses a promise to return the result. 381 382**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 383 384**System capability**: SystemCapability.Communication.Bluetooth.Core 385 386**Parameters** 387 388| Name | Type | Mandatory | Description | 389| -------- | ------ | ---- | ----------------------------------- | 390| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.| 391 392**Return value** 393 394| Type | Description | 395| ------------------- | ------------- | 396| Promise<Array<[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids12)>> | Promise used to return the result.| 397 398**Error codes** 399 400For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 401 402| ID| Error Message| 403| -------- | ---------------------------- | 404|201 | Permission denied. | 405|401 | Invalid parameter. | 406|801 | Capability not supported. | 407|2900001 | Service stopped. | 408|2900003 | Bluetooth disabled. | 409|2900099 | Operation failed. | 410 411**Example** 412 413```js 414import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 415try { 416 connection.getRemoteProfileUuids('XX:XX:XX:XX:XX:XX').then(() => { 417 console.info('getRemoteProfileUuids'); 418 }, (err: BusinessError) => { 419 console.error('getRemoteProfileUuids: errCode' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 420 }); 421} catch (err) { 422 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 423} 424``` 425 426 427## connection.getLocalName 428 429getLocalName(): string 430 431Obtains the name of the local Bluetooth device. 432 433**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 434 435**System capability**: SystemCapability.Communication.Bluetooth.Core 436 437**Return value** 438 439| Type | Description | 440| ------ | --------- | 441| string | Name of the local Bluetooth device obtained.| 442 443**Error codes** 444 445For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 446 447| ID| Error Message| 448| -------- | ---------------------------- | 449|201 | Permission denied. | 450|801 | Capability not supported. | 451|2900001 | Service stopped. | 452|2900099 | Operation failed. | 453 454**Example** 455 456```js 457import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 458try { 459 let localName: string = connection.getLocalName(); 460} catch (err) { 461 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 462} 463``` 464 465 466## connection.getPairedDevices 467 468getPairedDevices(): Array<string> 469 470Obtains the paired devices. 471 472**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 473 474**Atomic service API**: This API can be used in atomic services since API version 12. 475 476**System capability**: SystemCapability.Communication.Bluetooth.Core 477 478**Return value** 479 480| Type | Description | 481| ------------------- | ------------- | 482| Array<string> | Addresses of the paired Bluetooth devices.<br>- For security purposes, the device addresses obtained are random MAC addresses.<br>- The random MAC address remains unchanged after a device is paired successfully.<br>- The random address changes when the paired device is unpaired and scanned again or the Bluetooth service is turned off.| 483 484**Error codes** 485 486For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 487 488| ID| Error Message| 489| -------- | ---------------------------- | 490|201 | Permission denied. | 491|801 | Capability not supported. | 492|2900001 | Service stopped. | 493|2900003 | Bluetooth disabled. | 494|2900099 | Operation failed. | 495 496**Example** 497 498```js 499import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 500try { 501 let devices: Array<string> = connection.getPairedDevices(); 502} catch (err) { 503 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 504} 505``` 506 507 508## connection.getPairState<sup>11+</sup> 509 510getPairState(deviceId: string): BondState 511 512Obtains the Bluetooth pairing state. 513 514**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 515 516**Atomic service API**: This API can be used in atomic services since API version 12. 517 518**System capability**: SystemCapability.Communication.Bluetooth.Core 519 520**Parameters** 521 522| Name | Type | Mandatory | Description | 523| -------- | ------ | ---- | --------------------------------- | 524| deviceId | string | Yes | Address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 525 526**Return value** 527 528| Type | Description | 529| --------------------------- | -------- | 530| [BondState](#bondstate) | Bluetooth pairing state obtained.| 531 532**Error codes** 533 534For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 535 536| ID| Error Message| 537| -------- | ---------------------------- | 538|201 | Permission denied. | 539|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 540|801 | Capability not supported. | 541|2900001 | Service stopped. | 542|2900003 | Bluetooth disabled. | 543|2900099 | Operation failed. | 544 545**Example** 546 547```js 548import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 549try { 550 let res: connection.BondState = connection.getPairState("XX:XX:XX:XX:XX:XX"); 551 console.info('getPairState: ' + res); 552} catch (err) { 553 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 554} 555``` 556 557 558## connection.getProfileConnectionState 559 560getProfileConnectionState(profileId?: ProfileId): ProfileConnectionState 561 562Obtains the connection state of a Bluetooth profile. The **ProfileId** parameter is optional. 563- If **ProfileId** is specified, the connection state of the specified profile is returned. 564- If no **ProfileId** is specified, [STATE_CONNECTED](js-apis-bluetooth-constant.md#profileconnectionstate) is returned by any connected profile. If no profile is connected, [STATE_DISCONNECTED](js-apis-bluetooth-constant.md#profileconnectionstate) is returned. 565 566**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 567 568**System capability**: SystemCapability.Communication.Bluetooth.Core 569 570**Parameters** 571 572| Name | Type | Mandatory | Description | 573| --------- | --------- | ---- | ------------------------------------- | 574| profileId | [ProfileId](js-apis-bluetooth-constant.md#profileid) | No | ID of the target profile, for example, **PROFILE_A2DP_SOURCE**.| 575 576**Return value** 577 578| Type | Description | 579| ------------------------------------------------- | ------------------- | 580| [ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate) | Profile connection state obtained.| 581 582**Error codes** 583 584For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 585 586| ID| Error Message| 587| -------- | ---------------------------- | 588|201 | Permission denied. | 589|401 | Invalid parameter. Possible causes: 1. Incorrect parameter types. | 590|801 | Capability not supported. | 591|2900001 | Service stopped. | 592|2900003 | Bluetooth disabled. | 593|2900004 | Profile not supported. | 594|2900099 | Operation failed. | 595 596**Example** 597 598```js 599import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 600import { constant } from '@kit.ConnectivityKit'; 601try { 602 let result: connection.ProfileConnectionState = connection.getProfileConnectionState(constant.ProfileId.PROFILE_A2DP_SOURCE); 603} catch (err) { 604 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 605} 606``` 607 608 609## connection.setDevicePairingConfirmation 610 611setDevicePairingConfirmation(deviceId: string, accept: boolean): void 612 613Sets the device pairing confirmation. 614 615**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH (available only for system applications) 616 617**System capability**: SystemCapability.Communication.Bluetooth.Core 618 619**Parameters** 620 621| Name | Type | Mandatory | Description | 622| ------ | ------- | ---- | -------------------------------- | 623| deviceId | string | Yes | Address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 624| 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. | 625 626**Error codes** 627 628For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 629 630| ID| Error Message| 631| -------- | ---------------------------- | 632|201 | Permission denied. | 633|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 634|801 | Capability not supported. | 635|2900001 | Service stopped. | 636|2900003 | Bluetooth disabled. | 637|2900099 | Operation failed. | 638 639**Example** 640 641```js 642import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 643// Subscribe to the pinRequired event and configure the pairing confirmation after receiving a pairing request from the peer device. 644function onReceivePinRequiredEvent(data: connection.PinRequiredParam) { // data is the input parameter for the pairing request. 645 console.info('pin required = '+ JSON.stringify(data)); 646 connection.setDevicePairingConfirmation(data.deviceId, true); 647} 648try { 649 connection.on('pinRequired', onReceivePinRequiredEvent); 650} catch (err) { 651 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 652} 653``` 654 655 656## connection.setDevicePinCode 657 658setDevicePinCode(deviceId: string, code: string, callback: AsyncCallback<void>): void 659 660Sets the PIN for the device when **PinType** is **PIN_TYPE_ENTER_PIN_CODE** or **PIN_TYPE_PIN_16_DIGITS**. This API uses an asynchronous callback to return the result. 661 662**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 663 664**System capability**: SystemCapability.Communication.Bluetooth.Core 665 666**Parameters** 667 668| Name | Type | Mandatory | Description | 669| ------ | ------- | ---- | -------------------------------- | 670| deviceId | string | Yes | MAC address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 671| code | string | Yes | PIN to set. | 672| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 673 674**Error codes** 675 676For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 677 678| ID| Error Message| 679| -------- | ---------------------------- | 680|201 | Permission denied. | 681|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 682|801 | Capability not supported. | 683|2900001 | Service stopped. | 684|2900003 | Bluetooth disabled. | 685|2900099 | Operation failed. | 686 687**Example** 688 689```js 690import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 691// callback 692try { 693 connection.setDevicePinCode('11:22:33:44:55:66', '12345', (err: BusinessError) => { 694 console.info('setDevicePinCode,device name err:' + JSON.stringify(err)); 695 }); 696} catch (err) { 697 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 698} 699``` 700 701 702## connection.setDevicePinCode 703 704setDevicePinCode(deviceId: string, code: string): Promise<void> 705 706Sets the PIN for the device when **PinType** is **PIN_TYPE_ENTER_PIN_CODE** or **PIN_TYPE_PIN_16_DIGITS**. This API uses a promise to return the result. 707 708**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 709 710**System capability**: SystemCapability.Communication.Bluetooth.Core 711 712**Parameters** 713 714| Name | Type | Mandatory | Description | 715| ------ | ------- | ---- | -------------------------------- | 716| deviceId | string | Yes | MAC address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 717| code | string | Yes | PIN to set. | 718 719**Return value** 720 721| Type | Description | 722| ------------------- | ------------- | 723| Promise<void> | Promise used to return the result.| 724 725**Error codes** 726 727For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 728 729| ID| Error Message| 730| -------- | ---------------------------- | 731|201 | Permission denied. | 732|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 733|801 | Capability not supported. | 734|2900001 | Service stopped. | 735|2900003 | Bluetooth disabled. | 736|2900099 | Operation failed. | 737 738**Example** 739 740```js 741import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 742// promise 743try { 744 connection.setDevicePinCode('11:22:33:44:55:66', '12345').then(() => { 745 console.info('setDevicePinCode'); 746 }, (error: BusinessError) => { 747 console.info('setDevicePinCode: errCode:' + error.code + ',errMessage' + error.message); 748 }) 749 750} catch (err) { 751 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 752} 753``` 754 755 756## connection.setLocalName<sup>(deprecated)</sup> 757 758setLocalName(name: string): void 759 760Sets the name of the local Bluetooth device. 761 762> **NOTE**<br> 763> This API is supported since API version 10 and deprecated since API version 12. No substitute is provided. 764 765**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 766 767**System capability**: SystemCapability.Communication.Bluetooth.Core 768 769**Parameters** 770 771| Name | Type | Mandatory | Description | 772| ---- | ------ | ---- | --------------------- | 773| name | string | Yes | Bluetooth device name to set. It cannot exceed 248 bytes.| 774 775**Error codes** 776 777For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 778 779| ID| Error Message| 780| -------- | ---------------------------- | 781|201 | Permission denied. | 782|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 783|801 | Capability not supported. | 784|2900001 | Service stopped. | 785|2900003 | Bluetooth disabled. | 786|2900099 | Operation failed. | 787 788**Example** 789 790```js 791import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 792try { 793 connection.setLocalName('device_name'); 794} catch (err) { 795 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 796} 797``` 798 799 800## connection.setBluetoothScanMode 801 802setBluetoothScanMode(mode: ScanMode, duration: number): void 803 804Sets the Bluetooth scan mode so that the device can be discovered by a peer device. 805 806**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 807 808**System capability**: SystemCapability.Communication.Bluetooth.Core 809 810**Parameters** 811 812| Name | Type | Mandatory | Description | 813| -------- | --------------------- | ---- | ---------------------------- | 814| mode | [ScanMode](#scanmode) | Yes | Bluetooth scan mode to set. If the scan times out (**duration** is not **0**) when the scan mode is **SCAN_MODE_GENERAL_DISCOVERABLE**, the scan mode will be reset to **SCAN_MODE_CONNECTABLE**. | 815| duration | number | Yes | Duration (in seconds) in which the device can be discovered. The value **0** indicates unlimited time.| 816 817**Error codes** 818 819For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 820 821| ID| Error Message| 822| -------- | ---------------------------- | 823|201 | Permission denied. | 824|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 825|801 | Capability not supported. | 826|2900001 | Service stopped. | 827|2900003 | Bluetooth disabled. | 828|2900099 | Operation failed. | 829 830**Example** 831 832```js 833import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 834try { 835 // The device can be discovered and connected only when the discoverable and connectable mode is used. 836 connection.setBluetoothScanMode(connection.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100); 837} catch (err) { 838 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 839} 840``` 841 842 843## connection.getBluetoothScanMode 844 845getBluetoothScanMode(): ScanMode 846 847Obtains the Bluetooth scan mode. 848 849**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 850 851**System capability**: SystemCapability.Communication.Bluetooth.Core 852 853**Return value** 854 855| Type | Description | 856| --------------------- | ------- | 857| [ScanMode](#scanmode) | Bluetooth scan mode obtained.| 858 859**Error codes** 860 861For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 862 863| ID| Error Message| 864| -------- | ---------------------------- | 865|201 | Permission denied. | 866|801 | Capability not supported. | 867|2900001 | Service stopped. | 868|2900003 | Bluetooth disabled. | 869|2900099 | Operation failed. | 870 871**Example** 872 873```js 874import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 875try { 876 let scanMode: connection.ScanMode = connection.getBluetoothScanMode(); 877} catch (err) { 878 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 879} 880``` 881 882 883## connection.startBluetoothDiscovery 884 885startBluetoothDiscovery(): void 886 887Starts to discover Bluetooth devices. 888 889**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 890 891**Atomic service API**: This API can be used in atomic services since API version 12. 892 893**System capability**: SystemCapability.Communication.Bluetooth.Core 894 895**Error codes** 896 897For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 898 899| ID| Error Message| 900| -------- | ---------------------------- | 901|201 | Permission denied. | 902|801 | Capability not supported. | 903|2900001 | Service stopped. | 904|2900003 | Bluetooth disabled. | 905|2900099 | Operation failed. | 906 907**Example** 908 909```js 910import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 911function onReceiveEvent(data: Array<string>) { 912 console.info('data length' + data.length); 913} 914try { 915 connection.on('bluetoothDeviceFind', onReceiveEvent); 916 connection.startBluetoothDiscovery(); 917} catch (err) { 918 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 919} 920``` 921 922 923## connection.stopBluetoothDiscovery 924 925stopBluetoothDiscovery(): void 926 927Stops discovering Bluetooth devices. 928 929**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 930 931**Atomic service API**: This API can be used in atomic services since API version 12. 932 933**System capability**: SystemCapability.Communication.Bluetooth.Core 934 935**Error codes** 936 937For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 938 939| ID| Error Message| 940| -------- | ---------------------------- | 941|201 | Permission denied. | 942|801 | Capability not supported. | 943|2900001 | Service stopped. | 944|2900003 | Bluetooth disabled. | 945|2900099 | Operation failed. | 946 947**Example** 948 949```js 950import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 951try { 952 connection.stopBluetoothDiscovery(); 953} catch (err) { 954 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 955} 956``` 957 958 959## connection.isBluetoothDiscovering<sup>11+</sup> 960 961isBluetoothDiscovering(): boolean 962 963Checks whether Bluetooth discovery is enabled. 964 965**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 966 967**System capability**: SystemCapability.Communication.Bluetooth.Core 968 969**Return value** 970 971| Type | Description | 972| ------------------- | ------------- | 973| boolean | Returns **true** if Bluetooth discovery is enabled; returns **false** otherwise.| 974 975**Error codes** 976 977For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 978 979| ID| Error Message| 980| -------- | ---------------------------- | 981|201 | Permission denied. | 982|801 | Capability not supported. | 983|2900001 | Service stopped. | 984|2900003 | Bluetooth disabled. | 985|2900099 | Operation failed. | 986 987**Example** 988 989```js 990import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 991try { 992 let res: boolean = connection.isBluetoothDiscovering(); 993 console.info('isBluetoothDiscovering: ' + res); 994} catch (err) { 995 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 996} 997``` 998 999## connection.setRemoteDeviceName<sup>12+</sup> 1000 1001setRemoteDeviceName(deviceId: string, name: string): Promise<void> 1002 1003Sets the name of a remote Bluetooth device. This API uses a promise to return the result. 1004 1005**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1006 1007**Atomic service API**: This API can be used in atomic services since API version 12. 1008 1009**System capability**: SystemCapability.Communication.Bluetooth.Core 1010 1011**Parameters** 1012 1013| Name | Type | Mandatory | Description | 1014| -------- | ----------------------------------- | ---- | -------------------------------------- | 1015| deviceId | string | Yes | MAC address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 1016| name | string | Yes | Name of the peer device to set. The name cannot exceed 64 bytes. | 1017 1018**Return value** 1019 1020| Type | Description | 1021| ------------------- | ------------- | 1022| Promise<void> | Promise used to return the device name set. If the operation fails, an error code is returned.| 1023 1024**Error codes** 1025 1026For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1027 1028| ID| Error Message| 1029| -------- | ---------------------------- | 1030|201 | Permission denied. | 1031|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1032|2900001 | Service stopped. | 1033|2900003 | Bluetooth disabled. | 1034 1035**Example** 1036 1037```js 1038import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1039// promise 1040try { 1041 connection.setRemoteDeviceName('11:22:33:44:55:66', 'RemoteDeviceName').then(() => { 1042 console.info('setRemoteDeviceName success'); 1043 }, (error: BusinessError) => { 1044 console.error('setRemoteDeviceName: errCode:' + error.code + ',errMessage' + error.message); 1045 }) 1046 1047} catch (err) { 1048 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1049} 1050``` 1051 1052 1053## connection.getRemoteDeviceBatteryInfo<sup>12+</sup> 1054 1055getRemoteDeviceBatteryInfo(deviceId: string): Promise<BatteryInfo> 1056 1057obtains the battery information of a remote Bluetooth device. This API uses a promise to return the result. 1058 1059**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1060 1061**System capability**: SystemCapability.Communication.Bluetooth.Core 1062 1063**Parameters** 1064 1065| Name | Type | Mandatory | Description | 1066| ------ | ------- | ---- | -------------------------------- | 1067| deviceId | string | Yes | MAC address of the peer device, for example, **11:22:33:AA:BB:FF**.| 1068 1069**Return value** 1070 1071| Type | Description | 1072| ------------------- | ------------- | 1073| Promise<[BatteryInfo](#batteryinfo12)> | Promise used to return the battery information obtained.| 1074 1075**Error codes** 1076 1077For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1078 1079| ID| Error Message| 1080| -------- | ---------------------------- | 1081|201 | Permission denied. | 1082|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1083|2900001 | Service stopped. | 1084|2900003 | Bluetooth disabled. | 1085 1086**Example** 1087 1088```js 1089import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1090// promise 1091try { 1092 connection.getRemoteDeviceBatteryInfo('11:22:33:AA:BB:FF').then((data: connection.BatteryInfo) => { 1093 console.info('getRemoteDeviceBatteryInfo success, DeviceType:' + JSON.stringify(data)); 1094 }); 1095} catch (err) { 1096 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1097} 1098``` 1099 1100 1101## connection.on('batteryChange')<sup>12+</sup> 1102 1103on(type: 'batteryChange', callback: Callback<BatteryInfo>): void 1104 1105Subscribes to the changes in the battery information of a remote Bluetooth device. This API uses an asynchronous callback to return the result. 1106 1107**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1108 1109**System capability**: SystemCapability.Communication.Bluetooth.Core 1110 1111**Parameters** 1112 1113| Name | Type | Mandatory | Description | 1114| -------- | ----------------------------------- | ---- | -------------------------------------- | 1115| type | string | Yes | Event type. The value is **'batteryChange'**, which indicates the change in battery information of a remote Bluetooth device.| 1116| callback | Callback<[BatteryInfo](#batteryinfo12)> | Yes | Callback used to return the battery information. | 1117 1118**Error codes** 1119 1120For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1121 1122| ID| Error Message| 1123| -------- | ---------------------------- | 1124|201 | Permission denied. | 1125|2900099 | Operation failed. | 1126 1127**Example** 1128 1129```js 1130import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1131let onReceiveEvent: (data: connection.BatteryInfo) => void = (data: connection.BatteryInfo) => { 1132 console.info('BatteryInfo = '+ JSON.stringify(data)); 1133} 1134try { 1135 connection.on('batteryChange', onReceiveEvent); 1136} catch (err) { 1137 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1138} 1139``` 1140 1141 1142## connection.off('batteryChange')<sup>12+</sup> 1143 1144off(type: 'batteryChange', callback?: Callback<BatteryInfo>): void 1145 1146Unsubscribes from the changes in the battery information of a remote Bluetooth device. 1147 1148**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1149 1150**System capability**: SystemCapability.Communication.Bluetooth.Core 1151 1152**Parameters** 1153 1154| Name | Type | Mandatory | Description | 1155| -------- | ----------------------------------- | ---- | ---------------------------------------- | 1156| type | string | Yes | Event type. The value is **'batteryChange'**, which indicates the change in battery information of a remote Bluetooth device. | 1157| callback | Callback<[BatteryInfo](#batteryinfo12)> | No | Callback to unregister.| 1158 1159**Error codes** 1160 1161For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1162 1163| ID| Error Message| 1164| -------- | ---------------------------- | 1165|201 | Permission denied. | 1166|2900099 | Operation failed. | 1167 1168**Example** 1169 1170```js 1171import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1172let onReceiveEvent: (data: connection.BatteryInfo) => void = (data: connection.BatteryInfo) => { 1173 console.info('BatteryInfo = '+ JSON.stringify(data)); 1174} 1175try { 1176 connection.on('batteryChange', onReceiveEvent); 1177 connection.off('batteryChange', onReceiveEvent); 1178} catch (err) { 1179 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1180} 1181``` 1182 1183 1184## connection.on('bluetoothDeviceFind') 1185 1186on(type: 'bluetoothDeviceFind', callback: Callback<Array<string>>): void 1187 1188Subscribes to the Bluetooth device discovered. This API uses an asynchronous callback to return the result. 1189 1190**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1191 1192**Atomic service API**: This API can be used in atomic services since API version 12. 1193 1194**System capability**: SystemCapability.Communication.Bluetooth.Core 1195 1196**Parameters** 1197 1198| Name | Type | Mandatory | Description | 1199| -------- | ----------------------------------- | ---- | -------------------------------------- | 1200| type | string | Yes | Event type. The value is **bluetoothDeviceFind**, which indicates an event of discovering a Bluetooth device.| 1201| callback | Callback<Array<string>> | Yes | Callback used to return the discovered devices. You need to implement this callback. For security purposes, the device addresses are random MAC addresses. The random MAC address remains unchanged after a device is paired successfully. It changes when the paired device is unpaired and scanned again or the Bluetooth service is turned off. | 1202 1203**Error codes** 1204 1205For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1206 1207| ID| Error Message| 1208| -------- | ---------------------------- | 1209|201 | Permission denied. | 1210|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1211|801 | Capability not supported. | 1212|2900099 | Operation failed. | 1213 1214**Example** 1215 1216```js 1217import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1218function onReceiveEvent(data: Array<string>) { // data is an array of Bluetooth device addresses. 1219 console.info('bluetooth device find = '+ JSON.stringify(data)); 1220} 1221try { 1222 connection.on('bluetoothDeviceFind', onReceiveEvent); 1223} catch (err) { 1224 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1225} 1226``` 1227 1228 1229## connection.off('bluetoothDeviceFind') 1230 1231off(type: 'bluetoothDeviceFind', callback?: Callback<Array<string>>): void 1232 1233Unsubscribes from the Bluetooth device discovered. 1234 1235**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1236 1237**Atomic service API**: This API can be used in atomic services since API version 12. 1238 1239**System capability**: SystemCapability.Communication.Bluetooth.Core 1240 1241**Parameters** 1242 1243| Name | Type | Mandatory | Description | 1244| -------- | ----------------------------------- | ---- | ---------------------------------------- | 1245| type | string | Yes | Event type. The value is **bluetoothDeviceFind**, which indicates an event of discovering a Bluetooth device. | 1246| callback | Callback<Array<string>> | No | Callback to unregister. If this parameter is not set, this API unregisters all callbacks for the specified **type**.| 1247 1248**Error codes** 1249 1250For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1251 1252| ID| Error Message| 1253| -------- | ---------------------------- | 1254|201 | Permission denied. | 1255|801 | Capability not supported. | 1256|2900099 | Operation failed. | 1257 1258**Example** 1259 1260```js 1261import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1262function onReceiveEvent(data: Array<string>) { 1263 console.info('bluetooth device find = '+ JSON.stringify(data)); 1264} 1265try { 1266 connection.on('bluetoothDeviceFind', onReceiveEvent); 1267 connection.off('bluetoothDeviceFind', onReceiveEvent); 1268} catch (err) { 1269 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1270} 1271``` 1272 1273 1274## connection.on('bondStateChange') 1275 1276on(type: 'bondStateChange', callback: Callback<BondStateParam>): void 1277 1278Subscribes to Bluetooth pairing state changes. This API uses an asynchronous callback to return the result. 1279 1280**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1281 1282**System capability**: SystemCapability.Communication.Bluetooth.Core 1283 1284**Parameters** 1285 1286| Name | Type | Mandatory | Description | 1287| -------- | ---------------------------------------- | ---- | ------------------------------------ | 1288| type | string | Yes | Event type. The value is **bondStateChange**, which indicates a Bluetooth pairing state change event.| 1289| callback | Callback<[BondStateParam](#bondstateparam)> | Yes | Callback used to return the pairing state. You need to implement this callback. | 1290 1291**Error codes** 1292 1293For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1294 1295| ID| Error Message| 1296| -------- | ---------------------------- | 1297|201 | Permission denied. | 1298|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1299|801 | Capability not supported. | 1300|2900099 | Operation failed. | 1301 1302**Example** 1303 1304```js 1305import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1306function onReceiveEvent(data: connection.BondStateParam) { // data, as the input parameter of the callback, indicates the pairing state. 1307 console.info('pair state = '+ JSON.stringify(data)); 1308} 1309try { 1310 connection.on('bondStateChange', onReceiveEvent); 1311} catch (err) { 1312 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1313} 1314``` 1315 1316 1317## connection.off('bondStateChange') 1318 1319off(type: 'bondStateChange', callback?: Callback<BondStateParam>): void 1320 1321Unsubscribes from Bluetooth pairing state changes. 1322 1323**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1324 1325**System capability**: SystemCapability.Communication.Bluetooth.Core 1326 1327**Parameters** 1328 1329| Name | Type | Mandatory | Description | 1330| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1331| type | string | Yes | Event type. The value is **bondStateChange**, which indicates a Bluetooth pairing state change event. | 1332| callback | Callback<[BondStateParam](#bondstateparam)> | No | Callback to unregister. If this parameter is not set, this API unregisters all callbacks for the specified **type**.| 1333 1334**Error codes** 1335 1336For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1337 1338| ID| Error Message| 1339| -------- | ---------------------------- | 1340|201 | Permission denied. | 1341|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1342|801 | Capability not supported. | 1343|2900099 | Operation failed. | 1344 1345**Example** 1346 1347```js 1348import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1349function onReceiveEvent(data: connection.BondStateParam) { 1350 console.info('bond state = '+ JSON.stringify(data)); 1351} 1352try { 1353 connection.on('bondStateChange', onReceiveEvent); 1354 connection.off('bondStateChange', onReceiveEvent); 1355} catch (err) { 1356 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1357} 1358``` 1359 1360 1361## connection.on('pinRequired') 1362 1363on(type: 'pinRequired', callback: Callback<PinRequiredParam>): void 1364 1365Subscribes to the pairing request events of the remote Bluetooth device. This API uses an asynchronous callback to return the result. 1366 1367**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1368 1369**System capability**: SystemCapability.Communication.Bluetooth.Core 1370 1371**Parameters** 1372 1373| Name | Type | Mandatory | Description | 1374| -------- | ---------------------------------------- | ---- | -------------------------------- | 1375| type | string | Yes | Event type. The value **pinRequired** indicates a pairing request event. | 1376| callback | Callback<[PinRequiredParam](#pinrequiredparam)> | Yes | Callback used to return the pairing request. You need to implement this callback.| 1377 1378**Error codes** 1379 1380For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1381 1382| ID| Error Message| 1383| -------- | ---------------------------- | 1384|201 | Permission denied. | 1385|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1386|801 | Capability not supported. | 1387|2900099 | Operation failed. | 1388 1389**Example** 1390 1391```js 1392import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1393function onReceiveEvent(data: connection.PinRequiredParam) { // data is the pairing request parameter. 1394 console.info('pin required = '+ JSON.stringify(data)); 1395} 1396try { 1397 connection.on('pinRequired', onReceiveEvent); 1398} catch (err) { 1399 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1400} 1401``` 1402 1403 1404## connection.off('pinRequired') 1405 1406off(type: 'pinRequired', callback?: Callback<PinRequiredParam>): void 1407 1408Unsubscribes from the pairing request events of the remote Bluetooth device. 1409 1410**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1411 1412**System capability**: SystemCapability.Communication.Bluetooth.Core 1413 1414**Parameters** 1415 1416| Name | Type | Mandatory | Description | 1417| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1418| type | string | Yes | Event type. The value **pinRequired** indicates a pairing request event. | 1419| callback | Callback<[PinRequiredParam](#pinrequiredparam)> | No | Callback to unregister. The input parameter is the pairing request parameter. If this parameter is not set, this API unregisters all callbacks for the specified **type**.| 1420 1421**Error codes** 1422 1423For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1424 1425| ID| Error Message| 1426| -------- | ---------------------------- | 1427|201 | Permission denied. | 1428|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1429|801 | Capability not supported. | 1430|2900099 | Operation failed. | 1431 1432**Example** 1433 1434```js 1435import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1436function onReceiveEvent(data: connection.PinRequiredParam) { 1437 console.info('pin required = '+ JSON.stringify(data)); 1438} 1439try { 1440 connection.on('pinRequired', onReceiveEvent); 1441 connection.off('pinRequired', onReceiveEvent); 1442} catch (err) { 1443 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1444} 1445``` 1446 1447 1448## connection.on('discoveryResult')<sup>18+</sup> 1449 1450on(type: 'discoveryResult', callback: Callback<Array<DiscoveryResult>>): void 1451 1452Subscribes to the Bluetooth device discovered. This API uses an asynchronous callback to return the result. 1453 1454**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1455 1456**System capability**: SystemCapability.Communication.Bluetooth.Core 1457 1458**Parameters** 1459 1460| Name | Type | Mandatory | Description | 1461| -------- | ----------------------------------- | ---- | -------------------------------------- | 1462| type | string | Yes | Event type. The value is **discoveryResult**, which indicates information about the Bluetooth devices discovered.| 1463| callback | Callback<Array<[DiscoveryResult](#discoveryresult18)>> | Yes | Callback used to return the discovered devices. You need to implement this callback. | 1464 1465**Error codes** 1466 1467For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1468 1469| ID| Error Message| 1470| -------- | ---------------------------- | 1471|201 | Permission denied. | 1472|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1473|801 | Capability not supported. | 1474|2900099 | Operation failed. | 1475 1476**Example** 1477 1478```js 1479import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1480let onReceiveEvent: (data: Array<connection.DiscoveryResult>) => void = (data: Array<connection.DiscoveryResult>) => { // data is an array of Bluetooth devices discovered. 1481 console.info('bluetooth device find = '+ JSON.stringify(data)); 1482} 1483try { 1484 connection.on('discoveryResult', onReceiveEvent); 1485} catch (err) { 1486 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1487} 1488``` 1489 1490 1491## connection.off('discoveryResult')<sup>18+</sup> 1492 1493off(type: 'discoveryResult', callback?: Callback<Array<DiscoveryResult>>): void 1494 1495Unsubscribes from the Bluetooth device discovered. 1496 1497**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1498 1499**System capability**: SystemCapability.Communication.Bluetooth.Core 1500 1501**Parameters** 1502 1503| Name | Type | Mandatory | Description | 1504| -------- | ----------------------------------- | ---- | ---------------------------------------- | 1505| type | string | Yes | Event type. The value is **discoveryResult**, which indicates information about the Bluetooth devices discovered. | 1506| callback | Callback<Array<[DiscoveryResult](#discoveryresult18)>> | No | Callback to unregister. If this parameter is not set, this API unregisters all callbacks for the specified **type**. 1507 1508**Error codes** 1509 1510For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1511 1512| ID| Error Message| 1513| -------- | ---------------------------- | 1514|201 | Permission denied. | 1515|801 | Capability not supported. | 1516|2900099 | Operation failed. | 1517 1518**Example** 1519 1520```js 1521import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1522let onReceiveEvent: (data: Array<connection.DiscoveryResult>) => void = (data: Array<connection.DiscoveryResult>) => { // data is an array of Bluetooth devices discovered. 1523 console.info('bluetooth device find = '+ JSON.stringify(data)); 1524} 1525try { 1526 connection.on('discoveryResult', onReceiveEvent); 1527 connection.off('discoveryResult', onReceiveEvent); 1528} catch (err) { 1529 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1530} 1531``` 1532 1533 1534## connection.getLastConnectionTime<sup>15+</sup> 1535 1536getLastConnectionTime(deviceId: string): Promise<number> 1537 1538Obtains the timestamp of the most recent connection to the peer device. This API uses a promise to return the result. 1539 1540**System capability**: SystemCapability.Communication.Bluetooth.Core 1541 1542**Parameters** 1543 1544| Name | Type | Mandatory | Description | 1545| ------ | ------- | ---- | -------------------------------- | 1546| deviceId | string | Yes | MAC address of the peer device, for example, XX:XX:XX:XX:XX:XX.| 1547 1548**Return value** 1549 1550| Type | Description | 1551| ------------------- | ------------- | 1552| Promise<number> | Promise used to return the result, which is the timestamp of the most recent connection to the peer device.| 1553 1554**Error codes** 1555 1556For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1557 1558| ID| Error Message| 1559| -------- | ---------------------------- | 1560|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1561|801 | Capability not supported. | 1562|2900001 | Service stopped. | 1563|2900003 | Bluetooth disabled. | 1564|2900099 | Operation failed. | 1565 1566**Example** 1567 1568```js 1569import { connection } from '@kit.ConnectivityKit'; 1570// promise 1571try { 1572 connection.getLastConnectionTime('11:22:33:44:55:66').then((time: number) => { 1573 console.info('connectionTime: ${time}'); 1574 }); 1575} catch (err) { 1576 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1577} 1578``` 1579 1580## connection.connectAllowedProfiles<sup>16+</sup> 1581 1582connectAllowedProfiles(deviceId: string, callback: AsyncCallback<void>): void 1583 1584Connects all profiles allowed for a peer device. This API uses an asynchronous callback to return the result.<br>Call **pairDevice** to initiate pairing first. This API can be called only once within 30 seconds after each pairing is initiated.<br>Recommended usage: Subscribe to UUID_VALUE common event callbacks so that the application can receive a callback upon successful pairing of a Bluetooth device. You are advised to call **connectAllowedProfiles** in this callback. 1585 1586**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1587 1588**System capability**: SystemCapability.Communication.Bluetooth.Core 1589 1590**Parameters** 1591 1592| Name | Type | Mandatory | Description | 1593| -------- | ------ | ---- | ----------------------------------- | 1594| deviceId | string | Yes | Address of the peer device, for example, XX:XX:XX:XX:XX.| 1595| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 1596 1597**Error codes** 1598 1599For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1600 1601| ID| Error Message| 1602| -------- | ---------------------------- | 1603|201 | Permission denied. | 1604|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1605|801 | Capability not supported. | 1606|2900001 | Service stopped. | 1607|2900003 | Bluetooth disabled. | 1608|2900099 | Operation failed. | 1609 1610**Example** 1611 1612```js 1613import { commonEventManager, AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1614import { connection } from '@kit.ConnectivityKit'; 1615// Define a subscriber to save the created subscriber object for subsequent subscription and unsubscription. 1616let subscriber: commonEventManager.CommonEventSubscriber; 1617// Subscriber information. 1618let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { 1619 events: ["usual.event.bluetooth.remotedevice.UUID_VALUE"] 1620}; 1621// Subscribe to common event callbacks. 1622function SubscribeCB(err: BusinessError, data: commonEventManager.CommonEventData) { 1623 if (err) { 1624 console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); 1625 } else { 1626 console.info(`Succeeded in subscribing, data is ` + JSON.stringify(data)); 1627 // Before calling connectAllowedProfiles, ensure that the application has received the UUID_VALUE common event. 1628 try { 1629 connection.connectAllowedProfiles('68:13:24:79:4C:8C', (err: BusinessError) => { 1630 if (err) { 1631 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1632 return; 1633 } 1634 console.info('connectAllowedProfiles, err: ' + JSON.stringify(err)); 1635 }); 1636 } catch (err) { 1637 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1638 } 1639 } 1640} 1641// Callback for subscriber creation. 1642function createCB(err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) { 1643 if(!err) { 1644 console.info(`Succeeded in creating subscriber.`); 1645 subscriber = commonEventSubscriber; 1646 // Subscribe to common events. 1647 try { 1648 commonEventManager.subscribe(subscriber, SubscribeCB); 1649 } catch (error) { 1650 let err: BusinessError = error as BusinessError; 1651 console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); 1652 } 1653 } else { 1654 console.error(`Failed to create subscriber. Code is ${err.code}, message is ${err.message}`); 1655 } 1656} 1657 1658// Create a subscriber and subscribe to the common event callbacks. 1659try { 1660 commonEventManager.createSubscriber(subscribeInfo, createCB); 1661} catch (error) { 1662 let err: BusinessError = error as BusinessError; 1663 console.error(`Failed to create subscriber. Code is ${err.code}, message is ${err.message}`); 1664} 1665``` 1666 1667 1668## connection.connectAllowedProfiles<sup>16+</sup> 1669 1670connectAllowedProfiles(deviceId: string): Promise<void> 1671 1672Connects all profiles allowed for a peer device. This API uses a promise to return the result.<br>Call **pairDevice** to initiate pairing first. This API can be called only once within 30 seconds after each pairing is initiated.<br>Recommended usage: Subscribe to UUID_VALUE common event callbacks so that the application can receive a callback upon successful pairing of a Bluetooth device. You are advised to call **connectAllowedProfiles** in this callback. 1673 1674**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 1675 1676**System capability**: SystemCapability.Communication.Bluetooth.Core 1677 1678**Parameters** 1679 1680| Name | Type | Mandatory | Description | 1681| -------- | ------ | ---- | ----------------------------------- | 1682| deviceId | string | Yes | Address of the peer device, for example, XX:XX:XX:XX:XX.| 1683 1684**Return value** 1685 1686| Type | Description | 1687| ------------------------------------------------- | ------------------- | 1688| Promise<void> | Promise used to return the result.| 1689 1690**Error codes** 1691 1692For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bluetooth Error Codes](errorcode-bluetoothManager.md). 1693 1694| ID| Error Message| 1695| -------- | ---------------------------- | 1696|201 | Permission denied. | 1697|401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 1698|801 | Capability not supported. | 1699|2900001 | Service stopped. | 1700|2900003 | Bluetooth disabled. | 1701|2900099 | Operation failed. | 1702 1703**Example** 1704 1705```js 1706import { commonEventManager, AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 1707import { connection } from '@kit.ConnectivityKit'; 1708// Define a subscriber to save the created subscriber object for subsequent subscription and unsubscription. 1709let subscriber: commonEventManager.CommonEventSubscriber; 1710// Subscriber information. 1711let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { 1712 events: ["usual.event.bluetooth.remotedevice.UUID_VALUE"] 1713}; 1714// Subscribe to common event callbacks. 1715function SubscribeCB(err: BusinessError, data: commonEventManager.CommonEventData) { 1716 if (err) { 1717 console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); 1718 } else { 1719 console.info(`Succeeded in subscribing, data is ` + JSON.stringify(data)); 1720 // Before calling connectAllowedProfiles, ensure that the application has received the UUID_VALUE common event. 1721 try { 1722 connection.connectAllowedProfiles('68:13:24:79:4C:8C').then(() => { 1723 console.info('connectAllowedProfiles'); 1724 }, (err: BusinessError) => { 1725 console.error('connectAllowedProfiles:errCode' + err.code + ', errMessage: ' + err.message); 1726 }); 1727 } catch (err) { 1728 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 1729 } 1730 } 1731} 1732// Callback for subscriber creation. 1733function createCB(err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) { 1734 if(!err) { 1735 console.info(`Succeeded in creating subscriber.`); 1736 subscriber = commonEventSubscriber; 1737 // Subscribe to common events. 1738 try { 1739 commonEventManager.subscribe(subscriber, SubscribeCB); 1740 } catch (error) { 1741 let err: BusinessError = error as BusinessError; 1742 console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); 1743 } 1744 } else { 1745 console.error(`Failed to create subscriber. Code is ${err.code}, message is ${err.message}`); 1746 } 1747} 1748 1749// Create a subscriber and subscribe to the common event callbacks. 1750try { 1751 commonEventManager.createSubscriber(subscribeInfo, createCB); 1752} catch (error) { 1753 let err: BusinessError = error as BusinessError; 1754 console.error(`Failed to create subscriber. Code is ${err.code}, message is ${err.message}`); 1755} 1756``` 1757 1758## BondStateParam 1759 1760Represents the pairing state parameters. 1761 1762**System capability**: SystemCapability.Communication.Bluetooth.Core 1763 1764| Name | Type | Readable | Writable | Description | 1765| -------- | ------ | ---- | ---- | ----------- | 1766| deviceId | string | Yes | No | ID of the device to pair.| 1767| state | BondState | Yes | No | State of the device.| 1768| cause<sup>12+</sup>| [UnbondCause](#unbondcause12) | Yes| No| Cause of the pairing failure.| 1769 1770 1771## PinRequiredParam 1772 1773Represents the pairing request parameters. 1774 1775**System capability**: SystemCapability.Communication.Bluetooth.Core 1776 1777| Name | Type | Readable | Writable | Description | 1778| -------- | ------ | ---- | ---- | ----------- | 1779| deviceId | string | Yes | No | ID of the device to pair.| 1780| pinCode | string | Yes | No | Key for the device pairing. | 1781 1782 1783 1784## DeviceClass 1785 1786Represents the class of a Bluetooth device. 1787 1788**System capability**: SystemCapability.Communication.Bluetooth.Core 1789 1790| Name | Type | Readable | Writable | Description | 1791| --------------- | ----------------------------------- | ---- | ---- | ---------------- | 1792| majorClass | [MajorClass](js-apis-bluetooth-constant.md#majorclass) | Yes | No | Major class of the Bluetooth device. | 1793| majorMinorClass | [MajorMinorClass](js-apis-bluetooth-constant.md#majorminorclass) | Yes | No | Major and minor classes of the Bluetooth device.| 1794| classOfDevice | number | Yes | No | Class of the device. | 1795 1796 1797## BatteryInfo<sup>12+</sup> 1798 1799Represents the battery information. 1800 1801**System capability**: SystemCapability.Communication.Bluetooth.Core 1802 1803| Name | Type | Readable | Writable | Description | 1804| -------- | ------ | ---- | ---- | ----------- | 1805| batteryLevel | number | Yes | No | Battery level of the peer device. If the value is **-1**, there is no battery information. | 1806| leftEarBatteryLevel | number | Yes | No | Battery level of the left earphone. If the value is **-1**, there is no battery information. | 1807| leftEarChargeState | [DeviceChargeState](#devicechargestate12) | Yes | No | Charging state of the left earphone. | 1808| rightEarBatteryLevel | number | Yes | No | Battery level of the right earphone. If the value is **-1**, there is no battery information. | 1809| rightEarChargeState | [DeviceChargeState](#devicechargestate12) | Yes | No | Charging state of the right earphone. | 1810| boxBatteryLevel | number | Yes | No | Battery level of the earbud compartment. If the value is **-1**, there is no battery information. | 1811| boxChargeState | [DeviceChargeState](#devicechargestate12) | Yes | No | Charging state of the earbud compartment. | 1812 1813 1814## BluetoothTransport 1815 1816Enumerates the device types. The default device type is **TRANSPORT_BR_EDR**. 1817 1818**System capability**: SystemCapability.Communication.Bluetooth.Core 1819 1820| Name | Value | Description | 1821| -------------------------------- | ------ | --------------- | 1822| TRANSPORT_BR_EDR | 0 | Classic Bluetooth (BR/EDR) device.| 1823| TRANSPORT_LE | 1 | BLE device. | 1824 1825 1826## ScanMode 1827 1828Enumerates the scan modes. 1829 1830**System capability**: SystemCapability.Communication.Bluetooth.Core 1831 1832| Name | Value | Description | 1833| ---------------------------------------- | ---- | --------------- | 1834| SCAN_MODE_NONE | 0 | No scan mode. | 1835| SCAN_MODE_CONNECTABLE | 1 | Connectable mode. | 1836| SCAN_MODE_GENERAL_DISCOVERABLE | 2 | General discoverable mode. | 1837| SCAN_MODE_LIMITED_DISCOVERABLE | 3 | Limited discoverable mode. | 1838| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4 | General connectable and discoverable mode.| 1839| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5 | Limited connectable and discoverable mode.| 1840 1841 1842## BondState 1843 1844Enumerates the pairing states. 1845 1846**Atomic service API**: This API can be used in atomic services since API version 12. 1847 1848**System capability**: SystemCapability.Communication.Bluetooth.Core 1849 1850| Name | Value | Description | 1851| ------------------ | ---- | ------ | 1852| BOND_STATE_INVALID | 0 | Invalid pairing.| 1853| BOND_STATE_BONDING | 1 | Pairing. | 1854| BOND_STATE_BONDED | 2 | Paired. | 1855 1856 1857## UnbondCause<sup>12+</sup> 1858 1859Enumerates the possible causes of a pairing failure. 1860 1861**System capability**: SystemCapability.Communication.Bluetooth.Core 1862 1863| Name | Value | Description | 1864| ------------------ | ---- | ------ | 1865| USER_REMOVED | 0 | The user proactively removes the device.| 1866| REMOTE_DEVICE_DOWN | 1 | The peer device is shut down.| 1867| AUTH_FAILURE | 2 | The PIN is incorrect.| 1868| AUTH_REJECTED | 3 | The peer device authentication is rejected.| 1869| INTERNAL_ERROR | 4 | Internal error.| 1870 1871 1872## DeviceChargeState<sup>12+</sup> 1873 1874Enumerates the charging states. 1875 1876**System capability**: SystemCapability.Communication.Bluetooth.Core 1877 1878| Name | Value | Description | 1879| ------------------ | ---- | ------ | 1880| DEVICE_NORMAL_CHARGE_NOT_CHARGED | 0 | The device is not charged and does not support supercharging.| 1881| DEVICE_NORMAL_CHARGE_IN_CHARGING | 1 | The device is being charged and does not support supercharging.| 1882| DEVICE_SUPER_CHARGE_NOT_CHARGED | 2 | The device is not charged and supports supercharging.| 1883| DEVICE_SUPER_CHARGE_IN_CHARGING | 3 | The device is being charged and supports supercharging.| 1884 1885## DiscoveryResult<sup>18+</sup> 1886 1887Represents information about the discovered device. 1888 1889**System capability**: SystemCapability.Communication.Bluetooth.Core 1890 1891| Name | Type | Readable | Writable | Description | 1892| -------- | ------ | ---- | ---- | ----------- | 1893| deviceId | string | Yes | No | ID of the discovered device.| 1894| rssi | number | Yes | No | RSSI of the discovered device.| 1895| deviceName | string | Yes | No | Name of the discovered device.| 1896| deviceClass | DeviceClass | Yes | No | Bluetooth class of the discovered device.| 1897