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