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