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