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