1# @ohos.bluetoothManager (蓝牙)
2
3蓝牙模块提供了基础的传统蓝牙能力以及BLE的扫描、广播等功能。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> 从API Version 10 开始,该接口不再维护,推荐使用[`@ohos.bluetooth.ble`](js-apis-bluetooth-ble.md)等相关profile接口。
9
10
11
12## 导入模块
13
14```js
15import bluetoothManager from '@ohos.bluetoothManager';
16```
17
18
19## bluetoothManager.enableBluetooth<sup>(deprecated)</sup>
20
21enableBluetooth(): void
22
23开启蓝牙。
24
25> **说明:**<br/>
26> 从API version 9开始支持,从API version 10开始废弃。建议使用[access.enableBluetooth](js-apis-bluetooth-access.md#accessenablebluetooth)替代。
27
28**需要权限**:ohos.permission.ACCESS_BLUETOOTH
29
30
31**系统能力**:SystemCapability.Communication.Bluetooth.Core32
33**错误码**:
34
35以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
36
37| 错误码ID | 错误信息 |
38| -------- | ---------------------------- |
39|201 | Permission denied.                 |
40|801 | Capability not supported.          |
41|2900001 | Service stopped.                         |
42|2900099 | Operation failed.                        |
43
44**示例:**
45
46```js
47import { BusinessError } from '@ohos.base';
48try {
49    bluetoothManager.enableBluetooth();
50} catch (err) {
51    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
52}
53```
54
55
56## bluetoothManager.disableBluetooth<sup>(deprecated)</sup>
57
58disableBluetooth(): void
59
60关闭蓝牙。
61
62> **说明:**<br/>
63> 从API version 9开始支持,从API version 10开始废弃。建议使用[access.disableBluetooth](js-apis-bluetooth-access.md#accessdisablebluetooth)替代。
64
65**需要权限**:ohos.permission.ACCESS_BLUETOOTH
66
67**系统能力**:SystemCapability.Communication.Bluetooth.Core68
69**错误码**:
70
71以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
72
73| 错误码ID | 错误信息 |
74| -------- | ---------------------------- |
75|201 | Permission denied.                 |
76|801 | Capability not supported.          |
77|2900001 | Service stopped.                         |
78|2900099 | Operation failed.                        |
79
80**示例:**
81
82```js
83import { BusinessError } from '@ohos.base';
84try {
85    bluetoothManager.disableBluetooth();
86} catch (err) {
87    console.error("errCode:" + (err as BusinessError).code + ", errMessage:" + (err as BusinessError).message);
88}
89```
90
91
92## bluetoothManager.getLocalName<sup>(deprecated)</sup>
93
94getLocalName(): string
95
96获取蓝牙本地设备名称。
97
98> **说明:**<br/>
99> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.getLocalName](js-apis-bluetooth-connection.md#connectiongetlocalname)替代。
100
101**需要权限**:ohos.permission.ACCESS_BLUETOOTH
102
103**系统能力**:SystemCapability.Communication.Bluetooth.Core104
105**返回值:**
106
107| 类型     | 说明        |
108| ------ | --------- |
109| string | 蓝牙本地设备名称。 |
110
111**错误码**:
112
113以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
114
115| 错误码ID | 错误信息 |
116| -------- | ---------------------------- |
117|201 | Permission denied.                 |
118|801 | Capability not supported.          |
119|2900001 | Service stopped.                         |
120|2900099 | Operation failed.                        |
121
122**示例:**
123
124```js
125import { BusinessError } from '@ohos.base';
126try {
127    let localName: string = bluetoothManager.getLocalName();
128} catch (err) {
129    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
130}
131```
132
133
134## bluetoothManager.getState<sup>(deprecated)</sup>
135
136getState(): BluetoothState
137
138获取蓝牙开关状态。
139
140> **说明:**<br/>
141> 从API version 9开始支持,从API version 10开始废弃。建议使用[access.getState](js-apis-bluetooth-access.md#accessgetstate)替代。
142
143**需要权限**:ohos.permission.ACCESS_BLUETOOTH
144
145**系统能力**:SystemCapability.Communication.Bluetooth.Core146
147**返回值:**
148
149| 类型                                | 说明        |
150| --------------------------------- | --------- |
151| [BluetoothState](#bluetoothstatedeprecated) | 表示蓝牙开关状态。 |
152
153**错误码**:
154
155以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
156
157| 错误码ID | 错误信息 |
158| -------- | ---------------------------- |
159|201 | Permission denied.                 |
160|801 | Capability not supported.          |
161|2900001 | Service stopped.                         |
162|2900099 | Operation failed.                        |
163
164**示例:**
165
166```js
167import { BusinessError } from '@ohos.base';
168try {
169    let state: bluetoothManager.BluetoothState = bluetoothManager.getState();
170} catch (err) {
171    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
172}
173```
174
175
176## bluetoothManager.getBtConnectionState<sup>(deprecated)</sup>
177
178getBtConnectionState(): ProfileConnectionState
179
180获取蓝牙本端的Profile连接状态,例如:任意一个支持的Profile连接状态为已连接,则此接口返回状态为已连接。
181
182> **说明:**<br/>
183> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.getProfileConnectionState](js-apis-bluetooth-connection.md#connectiongetprofileconnectionstate)替代。
184
185**需要权限**:ohos.permission.ACCESS_BLUETOOTH
186
187**系统能力**:SystemCapability.Communication.Bluetooth.Core188
189**返回值:**
190
191| 类型                                       | 说明                  |
192| ---------------------------------------- | ------------------- |
193| [ProfileConnectionState](#profileconnectionstatedeprecated) | 表示蓝牙设备的Profile连接状态。 |
194
195**错误码**:
196
197以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
198
199| 错误码ID | 错误信息 |
200| -------- | ---------------------------- |
201|201 | Permission denied.                 |
202|801 | Capability not supported.          |
203|2900001 | Service stopped.                         |
204|2900003 | Bluetooth disabled.                 |
205|2900099 | Operation failed.                        |
206
207**示例:**
208
209```js
210import { BusinessError } from '@ohos.base';
211try {
212    let connectionState: bluetoothManager.ProfileConnectionState = bluetoothManager.getBtConnectionState();
213} catch (err) {
214    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
215}
216```
217
218
219## bluetoothManager.setLocalName<sup>(deprecated)</sup>
220
221setLocalName(name: string): void
222
223设置蓝牙本地设备名称。
224
225> **说明:**<br/>
226> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.setLocalName](js-apis-bluetooth-connection.md#connectionsetlocalname)替代。
227
228**需要权限**:ohos.permission.ACCESS_BLUETOOTH
229
230**系统能力**:SystemCapability.Communication.Bluetooth.Core231
232**参数:**
233
234| 参数名  | 类型     | 必填   | 说明                    |
235| ---- | ------ | ---- | --------------------- |
236| name | string | 是    | 要设置的蓝牙名称,最大长度为248字节数。 |
237
238**错误码**:
239
240以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
241
242| 错误码ID | 错误信息 |
243| -------- | ---------------------------- |
244|201 | Permission denied.                 |
245|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.              |
246|801 | Capability not supported.          |
247|2900001 | Service stopped.                         |
248|2900003 | Bluetooth disabled.                 |
249|2900099 | Operation failed.                        |
250
251**示例:**
252
253```js
254import { BusinessError } from '@ohos.base';
255try {
256    bluetoothManager.setLocalName('device_name');
257} catch (err) {
258    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
259}
260```
261
262
263## bluetoothManager.pairDevice<sup>(deprecated)</sup>
264
265pairDevice(deviceId: string): void
266
267发起蓝牙配对。
268
269> **说明:**<br/>
270> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.pairDevice](js-apis-bluetooth-connection.md#connectionpairdevice)替代。
271
272**需要权限**:ohos.permission.ACCESS_BLUETOOTH
273
274**系统能力**:SystemCapability.Communication.Bluetooth.Core275
276**参数:**
277
278| 参数名      | 类型     | 必填   | 说明                                  |
279| -------- | ------ | ---- | ----------------------------------- |
280| deviceId | string | 是    | 表示配对的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
281
282**错误码**:
283
284以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
285
286| 错误码ID | 错误信息 |
287| -------- | ---------------------------- |
288|201 | Permission denied.                 |
289|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
290|801 | Capability not supported.          |
291|2900001 | Service stopped.                         |
292|2900003 | Bluetooth disabled.                 |
293|2900099 | Operation failed.                        |
294
295**示例:**
296
297```js
298import { BusinessError } from '@ohos.base';
299try {
300    // 实际的地址可由扫描流程获取
301    bluetoothManager.pairDevice("XX:XX:XX:XX:XX:XX");
302} catch (err) {
303    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
304}
305```
306
307
308## bluetoothManager.getProfileConnectionState<sup>(deprecated)</sup>
309
310getProfileConnectionState(profileId: ProfileId): ProfileConnectionState
311
312依据ProfileId获取指定profile的连接状态。
313
314> **说明:**<br/>
315> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.getProfileConnectionState](js-apis-bluetooth-connection.md#connectiongetprofileconnectionstate)替代。
316
317**需要权限**:ohos.permission.ACCESS_BLUETOOTH
318
319**系统能力**:SystemCapability.Communication.Bluetooth.Core320
321**参数:**
322
323| 参数名       | 类型        | 必填   | 说明                                    |
324| --------- | --------- | ---- | ------------------------------------- |
325| profileId | ProfileId | 是    | 表示profile的枚举值,例如:PROFILE_A2DP_SOURCE。 |
326
327**返回值:**
328
329| 类型                                              | 说明                |
330| ------------------------------------------------- | ------------------- |
331| [ProfileConnectionState](#profileconnectionstatedeprecated) | profile的连接状态。 |
332
333**错误码**:
334
335以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
336
337| 错误码ID | 错误信息 |
338| -------- | ---------------------------- |
339|201 | Permission denied.                 |
340|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.           |
341|801 | Capability not supported.          |
342|2900001 | Service stopped.                         |
343|2900003 | Bluetooth disabled.                 |
344|2900004 | Profile not supported.                |
345|2900099 | Operation failed.                        |
346
347**示例:**
348
349```js
350import { BusinessError } from '@ohos.base';
351try {
352    let result: bluetoothManager.ProfileConnectionState = bluetoothManager.getProfileConnectionState(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE);
353} catch (err) {
354    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
355}
356```
357
358
359
360## bluetoothManager.getRemoteDeviceName<sup>(deprecated)</sup>
361
362getRemoteDeviceName(deviceId: string): string
363
364获取对端蓝牙设备的名称。
365
366> **说明:**<br/>
367> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.getRemoteDeviceName](js-apis-bluetooth-connection.md#connectiongetremotedevicename)替代。
368
369**需要权限**:ohos.permission.ACCESS_BLUETOOTH
370
371**系统能力**:SystemCapability.Communication.Bluetooth.Core372
373**参数:**
374
375| 参数名      | 类型     | 必填   | 说明                                |
376| -------- | ------ | ---- | --------------------------------- |
377| deviceId | string | 是    | 表示远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
378
379**返回值:**
380
381| 类型     | 说明            |
382| ------ | ------------- |
383| string | 以字符串格式返回设备名称。 |
384
385**错误码**:
386
387以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
388
389| 错误码ID | 错误信息 |
390| -------- | ---------------------------- |
391|201 | Permission denied.                 |
392|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
393|801 | Capability not supported.          |
394|2900001 | Service stopped.                         |
395|2900003 | Bluetooth disabled.                 |
396|2900099 | Operation failed.                        |
397
398**示例:**
399
400```js
401import { BusinessError } from '@ohos.base';
402try {
403    let remoteDeviceName: string = bluetoothManager.getRemoteDeviceName("XX:XX:XX:XX:XX:XX");
404} catch (err) {
405    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
406}
407```
408
409
410## bluetoothManager.getRemoteDeviceClass<sup>(deprecated)</sup>
411
412getRemoteDeviceClass(deviceId: string): DeviceClass
413
414获取对端蓝牙设备的类别。
415
416> **说明:**<br/>
417> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.getRemoteDeviceClass](js-apis-bluetooth-connection.md#connectiongetremotedeviceclass)替代。
418
419**需要权限**:ohos.permission.ACCESS_BLUETOOTH
420
421**系统能力**:SystemCapability.Communication.Bluetooth.Core422
423**参数:**
424
425| 参数名      | 类型     | 必填   | 说明                                |
426| -------- | ------ | ---- | --------------------------------- |
427| deviceId | string | 是    | 表示远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
428
429**返回值:**
430
431| 类型                          | 说明       |
432| --------------------------- | -------- |
433| [DeviceClass](#deviceclassdeprecated) | 远程设备的类别。 |
434
435**错误码**:
436
437以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
438
439| 错误码ID | 错误信息 |
440| -------- | ---------------------------- |
441|201 | Permission denied.                 |
442|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
443|801 | Capability not supported.          |
444|2900001 | Service stopped.                         |
445|2900003 | Bluetooth disabled.                 |
446|2900099 | Operation failed.                        |
447
448**示例:**
449
450```js
451import { BusinessError } from '@ohos.base';
452try {
453    let remoteDeviceClass: bluetoothManager.DeviceClass  = bluetoothManager.getRemoteDeviceClass("XX:XX:XX:XX:XX:XX");
454} catch (err) {
455    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
456}
457```
458
459
460## bluetoothManager.getPairedDevices<sup>(deprecated)</sup>
461
462getPairedDevices(): Array&lt;string&gt;
463
464获取蓝牙配对列表。
465
466> **说明:**<br/>
467> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.getPairedDevices](js-apis-bluetooth-connection.md#connectiongetpaireddevices)替代。
468
469**需要权限**:ohos.permission.ACCESS_BLUETOOTH
470
471**系统能力**:SystemCapability.Communication.Bluetooth.Core472
473**返回值:**
474
475| 类型                  | 说明            |
476| ------------------- | ------------- |
477| Array&lt;string&gt; | 已配对蓝牙设备的地址列表。 |
478
479**错误码**:
480
481以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
482
483| 错误码ID | 错误信息 |
484| -------- | ---------------------------- |
485|201 | Permission denied.                 |
486|801 | Capability not supported.          |
487|2900001 | Service stopped.                         |
488|2900003 | Bluetooth disabled.                 |
489|2900099 | Operation failed.                        |
490
491**示例:**
492
493```js
494import { BusinessError } from '@ohos.base';
495try {
496    let devices: Array<string> = bluetoothManager.getPairedDevices();
497} catch (err) {
498    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
499}
500```
501
502
503## bluetoothManager.setBluetoothScanMode<sup>(deprecated)</sup>
504
505setBluetoothScanMode(mode: ScanMode, duration: number): void
506
507设置蓝牙扫描模式,可以被远端设备发现。
508
509> **说明:**<br/>
510> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.setBluetoothScanMode](js-apis-bluetooth-connection.md#connectionsetbluetoothscanmode)替代。
511
512**需要权限**:ohos.permission.ACCESS_BLUETOOTH
513
514**系统能力**:SystemCapability.Communication.Bluetooth.Core515
516**参数:**
517
518| 参数名      | 类型                    | 必填   | 说明                           |
519| -------- | --------------------- | ---- | ---------------------------- |
520| mode     | [ScanMode](#scanmodedeprecated) | 是    | 蓝牙扫描模式。                      |
521| duration | number                | 是    | 设备可被发现的持续时间,单位为毫秒;设置为0则持续可发现。 |
522
523**错误码**:
524
525以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
526
527| 错误码ID | 错误信息 |
528| -------- | ---------------------------- |
529|201 | Permission denied.                 |
530|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.             |
531|801 | Capability not supported.          |
532|2900001 | Service stopped.                         |
533|2900003 | Bluetooth disabled.                 |
534|2900099 | Operation failed.                        |
535
536**示例:**
537
538```js
539import { BusinessError } from '@ohos.base';
540try {
541    // 设置为可连接可发现才可被远端设备扫描到,可以连接。
542    bluetoothManager.setBluetoothScanMode(bluetoothManager.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100);
543} catch (err) {
544    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
545}
546```
547
548
549## bluetoothManager.getBluetoothScanMode<sup>(deprecated)</sup>
550
551getBluetoothScanMode(): ScanMode
552
553获取蓝牙扫描模式。
554
555> **说明:**<br/>
556> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.getBluetoothScanMode](js-apis-bluetooth-connection.md#connectiongetbluetoothscanmode)替代。
557
558**需要权限**:ohos.permission.ACCESS_BLUETOOTH
559
560**系统能力**:SystemCapability.Communication.Bluetooth.Core561
562**返回值:**
563
564| 类型                    | 说明      |
565| --------------------- | ------- |
566| [ScanMode](#scanmodedeprecated) | 蓝牙扫描模式。 |
567
568**错误码**:
569
570以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
571
572| 错误码ID | 错误信息 |
573| -------- | ---------------------------- |
574|201 | Permission denied.                 |
575|801 | Capability not supported.          |
576|2900001 | Service stopped.                         |
577|2900003 | Bluetooth disabled.                 |
578|2900099 | Operation failed.                        |
579
580**示例:**
581
582```js
583import { BusinessError } from '@ohos.base';
584try {
585    let scanMode: bluetoothManager.ScanMode = bluetoothManager.getBluetoothScanMode();
586} catch (err) {
587    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
588}
589```
590
591
592## bluetoothManager.startBluetoothDiscovery<sup>(deprecated)</sup>
593
594startBluetoothDiscovery(): void
595
596开启蓝牙扫描,可以发现远端设备。
597
598> **说明:**<br/>
599> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.startBluetoothDiscovery](js-apis-bluetooth-connection.md#connectionstartbluetoothdiscovery)替代。
600
601**需要权限**:ohos.permission.ACCESS_BLUETOOTH
602
603**系统能力**:SystemCapability.Communication.Bluetooth.Core604
605**错误码**:
606
607以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
608
609| 错误码ID | 错误信息 |
610| -------- | ---------------------------- |
611|201 | Permission denied.                 |
612|801 | Capability not supported.          |
613|2900001 | Service stopped.                         |
614|2900003 | Bluetooth disabled.                 |
615|2900099 | Operation failed.                        |
616
617**示例:**
618
619```js
620import { BusinessError } from '@ohos.base';
621let deviceId: Array<string>;
622function onReceiveEvent(data: Array<string>) {
623    deviceId = data;
624}
625try {
626    bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
627    bluetoothManager.startBluetoothDiscovery();
628} catch (err) {
629    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
630}
631```
632
633
634## bluetoothManager.stopBluetoothDiscovery<sup>(deprecated)</sup>
635
636stopBluetoothDiscovery(): void
637
638关闭蓝牙扫描。
639
640> **说明:**<br/>
641> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.stopBluetoothDiscovery](js-apis-bluetooth-connection.md#connectionstopbluetoothdiscovery)替代。
642
643**需要权限**:ohos.permission.ACCESS_BLUETOOTH
644
645**系统能力**:SystemCapability.Communication.Bluetooth.Core646
647**错误码**:
648
649以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
650
651| 错误码ID | 错误信息 |
652| -------- | ---------------------------- |
653|201 | Permission denied.                 |
654|801 | Capability not supported.          |
655|2900001 | Service stopped.                         |
656|2900003 | Bluetooth disabled.                 |
657|2900099 | Operation failed.                        |
658
659**示例:**
660
661```js
662import { BusinessError } from '@ohos.base';
663try {
664    bluetoothManager.stopBluetoothDiscovery();
665} catch (err) {
666    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
667}
668```
669
670
671## bluetoothManager.setDevicePairingConfirmation<sup>(deprecated)</sup>
672
673setDevicePairingConfirmation(device: string, accept: boolean): void
674
675设置设备配对请求确认。
676
677> **说明:**<br/>
678> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.setDevicePairingConfirmation](js-apis-bluetooth-connection.md#connectionsetdevicepairingconfirmation)替代。
679
680**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH(该权限仅系统应用可申请)
681
682**系统能力**:SystemCapability.Communication.Bluetooth.Core683
684**参数:**
685
686| 参数名    | 类型      | 必填   | 说明                               |
687| ------ | ------- | ---- | -------------------------------- |
688| device | string  | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
689| accept | boolean | 是    | 接受配对请求设置为true,否则设置为false。        |
690
691**错误码**:
692
693以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
694
695| 错误码ID | 错误信息 |
696| -------- | ---------------------------- |
697|201 | Permission denied.                 |
698|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
699|801 | Capability not supported.          |
700|2900001 | Service stopped.                         |
701|2900003 | Bluetooth disabled.                 |
702|2900099 | Operation failed.                        |
703
704**示例:**
705
706```js
707import { BusinessError } from '@ohos.base';
708// 订阅“pinRequired”配对请求事件,收到远端配对请求后设置配对确认
709function onReceivePinRequiredEvent(data: bluetoothManager.PinRequiredParam) { // data为配对请求的入参,配对请求参数
710    console.info('pin required  = '+ JSON.stringify(data));
711    bluetoothManager.setDevicePairingConfirmation(data.deviceId, true);
712}
713try {
714    bluetoothManager.on("pinRequired", onReceivePinRequiredEvent);
715} catch (err) {
716    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
717}
718```
719
720
721## bluetoothManager.on('bluetoothDeviceFind')<sup>(deprecated)</sup>
722
723on(type: 'bluetoothDeviceFind', callback: Callback&lt;Array&lt;string&gt;&gt;): void
724
725订阅蓝牙设备发现上报事件。
726
727> **说明:**<br/>
728> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.on('bluetoothDeviceFind')](js-apis-bluetooth-connection.md#connectiononbluetoothdevicefind)替代。
729
730**需要权限**:ohos.permission.ACCESS_BLUETOOTH
731
732**系统能力**:SystemCapability.Communication.Bluetooth.Core733
734**参数:**
735
736| 参数名      | 类型                                  | 必填   | 说明                                     |
737| -------- | ----------------------------------- | ---- | -------------------------------------- |
738| type     | string                              | 是    | 填写"bluetoothDeviceFind"字符串,表示蓝牙设备发现事件。 |
739| callback | Callback&lt;Array&lt;string&gt;&gt; | 是    | 表示回调函数的入参,发现的设备集合。回调函数由用户创建通过该接口注册。    |
740
741**错误码**:
742
743以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
744
745| 错误码ID | 错误信息 |
746| -------- | ---------------------------- |
747|201 | Permission denied.                 |
748|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
749|801 | Capability not supported.          |
750|2900099 | Operation failed.                        |
751
752**示例:**
753
754```js
755import { BusinessError } from '@ohos.base';
756function onReceiveEvent(data: Array<string>) { // data为蓝牙设备地址集合
757    console.info('bluetooth device find = '+ JSON.stringify(data));
758}
759try {
760    bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
761} catch (err) {
762    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
763}
764```
765
766
767## bluetoothManager.off('bluetoothDeviceFind')<sup>(deprecated)</sup>
768
769off(type: 'bluetoothDeviceFind', callback?: Callback&lt;Array&lt;string&gt;&gt;): void
770
771取消订阅蓝牙设备发现上报事件。
772
773> **说明:**<br/>
774> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.off('bluetoothDeviceFind')](js-apis-bluetooth-connection.md#connectionoffbluetoothdevicefind)替代。
775
776**需要权限**:ohos.permission.ACCESS_BLUETOOTH
777
778**系统能力**:SystemCapability.Communication.Bluetooth.Core779
780**参数:**
781
782| 参数名      | 类型                                  | 必填   | 说明                                       |
783| -------- | ----------------------------------- | ---- | ---------------------------------------- |
784| type     | string                              | 是    | 填写"bluetoothDeviceFind"字符串,表示蓝牙设备发现事件。   |
785| callback | Callback&lt;Array&lt;string&gt;&gt; | 否    | 表示取消订阅蓝牙设备发现事件上报。不填该参数则取消订阅该type对应的所有回调。 |
786
787**错误码**:
788
789以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
790
791| 错误码ID | 错误信息 |
792| -------- | ---------------------------- |
793|201 | Permission denied.                 |
794|801 | Capability not supported.          |
795|2900099 | Operation failed.                        |
796
797**示例:**
798
799```js
800import { BusinessError } from '@ohos.base';
801function onReceiveEvent(data: Array<string>) {
802    console.info('bluetooth device find = '+ JSON.stringify(data));
803}
804try {
805    bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
806    bluetoothManager.off('bluetoothDeviceFind', onReceiveEvent);
807} catch (err) {
808    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
809}
810```
811
812
813## bluetoothManager.on('pinRequired')<sup>(deprecated)</sup>
814
815on(type: 'pinRequired', callback: Callback&lt;PinRequiredParam&gt;): void
816
817订阅远端蓝牙设备的配对请求事件。
818
819> **说明:**<br/>
820> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.on('pinRequired')](js-apis-bluetooth-connection.md#connectiononpinrequired)替代。
821
822**需要权限**:ohos.permission.ACCESS_BLUETOOTH
823
824**系统能力**:SystemCapability.Communication.Bluetooth.Core825
826**参数:**
827
828| 参数名      | 类型                                       | 必填   | 说明                               |
829| -------- | ---------------------------------------- | ---- | -------------------------------- |
830| type     | string                                   | 是    | 填写"pinRequired"字符串,表示配对请求事件。     |
831| callback | Callback&lt;[PinRequiredParam](#pinrequiredparamdeprecated)&gt; | 是    | 表示回调函数的入参,配对请求。回调函数由用户创建通过该接口注册。 |
832
833**错误码**:
834
835以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
836
837| 错误码ID | 错误信息 |
838| -------- | ---------------------------- |
839|201 | Permission denied.                 |
840|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
841|801 | Capability not supported.          |
842|2900099 | Operation failed.                        |
843
844**示例:**
845
846```js
847import { BusinessError } from '@ohos.base';
848function onReceiveEvent(data: bluetoothManager.PinRequiredParam) { // data为配对请求参数
849    console.info('pin required = '+ JSON.stringify(data));
850}
851try {
852    bluetoothManager.on('pinRequired', onReceiveEvent);
853} catch (err) {
854    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
855}
856```
857
858
859## bluetoothManager.off('pinRequired')<sup>(deprecated)</sup>
860
861off(type: 'pinRequired', callback?: Callback&lt;PinRequiredParam&gt;): void
862
863取消订阅远端蓝牙设备的配对请求事件。
864
865> **说明:**<br/>
866> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.off('pinRequired')](js-apis-bluetooth-connection.md#connectionoffpinrequired)替代。
867
868**需要权限**:ohos.permission.ACCESS_BLUETOOTH
869
870**系统能力**:SystemCapability.Communication.Bluetooth.Core871
872**参数:**
873
874| 参数名      | 类型                                       | 必填   | 说明                                       |
875| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
876| type     | string                                   | 是    | 填写"pinRequired"字符串,表示配对请求事件。             |
877| callback | Callback&lt;[PinRequiredParam](#pinrequiredparamdeprecated)&gt; | 否    | 表示取消订阅蓝牙配对请求事件上报,入参为配对请求参数。不填该参数则取消订阅该type对应的所有回调。 |
878
879**错误码**:
880
881以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
882
883| 错误码ID | 错误信息 |
884| -------- | ---------------------------- |
885|201 | Permission denied.                 |
886|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
887|801 | Capability not supported.          |
888|2900099 | Operation failed.                        |
889
890**示例:**
891
892```js
893import { BusinessError } from '@ohos.base';
894function onReceiveEvent(data: bluetoothManager.PinRequiredParam) {
895    console.info('pin required = '+ JSON.stringify(data));
896}
897try {
898    bluetoothManager.on('pinRequired', onReceiveEvent);
899    bluetoothManager.off('pinRequired', onReceiveEvent);
900} catch (err) {
901    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
902}
903```
904
905
906## bluetoothManager.on('bondStateChange')<sup>(deprecated)</sup>
907
908on(type: 'bondStateChange', callback: Callback&lt;BondStateParam&gt;): void
909
910订阅蓝牙配对状态改变事件。
911
912> **说明:**<br/>
913> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.on('bondStateChange')](js-apis-bluetooth-connection.md#connectiononbondstatechange)替代。
914
915**需要权限**:ohos.permission.ACCESS_BLUETOOTH
916
917**系统能力**:SystemCapability.Communication.Bluetooth.Core918
919**参数:**
920
921| 参数名      | 类型                                       | 必填   | 说明                                   |
922| -------- | ---------------------------------------- | ---- | ------------------------------------ |
923| type     | string                                   | 是    | 填写"bondStateChange"字符串,表示蓝牙配对状态改变事件。 |
924| callback | Callback&lt;[BondStateParam](#bondstateparamdeprecated)&gt; | 是    | 表示回调函数的入参,配对的状态。回调函数由用户创建通过该接口注册。    |
925
926**错误码**:
927
928以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
929
930| 错误码ID | 错误信息 |
931| -------- | ---------------------------- |
932|201 | Permission denied.                 |
933|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
934|801 | Capability not supported.          |
935|2900099 | Operation failed.                        |
936
937**示例:**
938
939```js
940import { BusinessError } from '@ohos.base';
941function onReceiveEvent(data: bluetoothManager.BondStateParam) { // data为回调函数入参,表示配对的状态
942    console.info('pair state = '+ JSON.stringify(data));
943}
944try {
945    bluetoothManager.on('bondStateChange', onReceiveEvent);
946} catch (err) {
947    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
948}
949```
950
951
952## bluetoothManager.off('bondStateChange')<sup>(deprecated)</sup>
953
954off(type: 'bondStateChange', callback?: Callback&lt;BondStateParam&gt;): void
955
956取消订阅蓝牙配对状态改变事件。
957
958> **说明:**<br/>
959> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.off('bondStateChange')](js-apis-bluetooth-connection.md#connectionoffbondstatechange)替代。
960
961**需要权限**:ohos.permission.ACCESS_BLUETOOTH
962
963**系统能力**:SystemCapability.Communication.Bluetooth.Core964
965**参数:**
966
967| 参数名      | 类型                                       | 必填   | 说明                                       |
968| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
969| type     | string                                   | 是    | 填写"bondStateChange"字符串,表示蓝牙配对状态改变事件。     |
970| callback | Callback&lt;[BondStateParam](#bondstateparamdeprecated)&gt; | 否    | 表示取消订阅蓝牙配对状态改变事件上报。不填该参数则取消订阅该type对应的所有回调。 |
971
972**错误码**:
973
974以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
975
976| 错误码ID | 错误信息 |
977| -------- | ---------------------------- |
978|201 | Permission denied.                 |
979|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
980|801 | Capability not supported.          |
981|2900099 | Operation failed.                        |
982
983**示例:**
984
985```js
986import { BusinessError } from '@ohos.base';
987function onReceiveEvent(data: bluetoothManager.BondStateParam) {
988    console.info('bond state = '+ JSON.stringify(data));
989}
990try {
991    bluetoothManager.on('bondStateChange', onReceiveEvent);
992    bluetoothManager.off('bondStateChange', onReceiveEvent);
993} catch (err) {
994    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
995}
996```
997
998
999## bluetoothManager.on('stateChange')<sup>(deprecated)</sup>
1000
1001on(type: 'stateChange', callback: Callback&lt;BluetoothState&gt;): void
1002
1003订阅蓝牙设备开关状态事件。
1004
1005> **说明:**<br/>
1006> 从API version 9开始支持,从API version 10开始废弃。建议使用[access.on('stateChange')](js-apis-bluetooth-access.md#accessonstatechange)替代。
1007
1008**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1009
1010**系统能力**:SystemCapability.Communication.Bluetooth.Core1011
1012**参数:**
1013
1014| 参数名      | 类型                                       | 必填   | 说明                               |
1015| -------- | ---------------------------------------- | ---- | -------------------------------- |
1016| type     | string                                   | 是    | 填写"stateChange"字符串,表示蓝牙状态改变事件。   |
1017| callback | Callback&lt;[BluetoothState](#bluetoothstatedeprecated)&gt; | 是    | 表示回调函数的入参,蓝牙状态。回调函数由用户创建通过该接口注册。 |
1018
1019**错误码**:
1020
1021以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1022
1023| 错误码ID | 错误信息 |
1024| -------- | ---------------------------- |
1025|201 | Permission denied.                 |
1026|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
1027|801 | Capability not supported.          |
1028|2900099 | Operation failed.                        |
1029
1030**示例:**
1031
1032```js
1033import { BusinessError } from '@ohos.base';
1034function onReceiveEvent(data: bluetoothManager.BluetoothState) {
1035    console.info('bluetooth state = '+ JSON.stringify(data));
1036}
1037try {
1038    bluetoothManager.on('stateChange', onReceiveEvent);
1039} catch (err) {
1040    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1041}
1042```
1043
1044
1045## bluetoothManager.off('stateChange')<sup>(deprecated)</sup>
1046
1047off(type: 'stateChange', callback?: Callback&lt;BluetoothState&gt;): void
1048
1049取消订阅蓝牙设备开关状态事件。
1050
1051> **说明:**<br/>
1052> 从API version 9开始支持,从API version 10开始废弃。建议使用[access.off('stateChange')](js-apis-bluetooth-access.md#accessoffstatechange)替代。
1053
1054**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1055
1056**系统能力**:SystemCapability.Communication.Bluetooth.Core1057
1058**参数:**
1059
1060| 参数名      | 类型                                       | 必填   | 说明                                       |
1061| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1062| type     | string                                   | 是    | 填写"stateChange"字符串,表示蓝牙状态改变事件。           |
1063| callback | Callback&lt;[BluetoothState](#bluetoothstatedeprecated)&gt; | 否    | 表示取消订阅蓝牙状态改变事件上报。不填该参数则取消订阅该type对应的所有回调。 |
1064
1065**错误码**:
1066
1067以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1068
1069| 错误码ID | 错误信息 |
1070| -------- | ---------------------------- |
1071|201 | Permission denied.                 |
1072|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
1073|801 | Capability not supported.          |
1074|2900099 | Operation failed.                        |
1075
1076**示例:**
1077
1078```js
1079import { BusinessError } from '@ohos.base';
1080function onReceiveEvent(data: bluetoothManager.BluetoothState) {
1081    console.info('bluetooth state = '+ JSON.stringify(data));
1082}
1083try {
1084    bluetoothManager.on('stateChange', onReceiveEvent);
1085    bluetoothManager.off('stateChange', onReceiveEvent);
1086} catch (err) {
1087    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1088}
1089```
1090
1091
1092## bluetoothManager.sppListen<sup>(deprecated)</sup>
1093
1094sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
1095
1096创建一个服务端监听Socket。
1097
1098> **说明:**<br/>
1099> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.sppListen](js-apis-bluetooth-socket.md#socketspplisten)替代。
1100
1101**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1102
1103**系统能力**:SystemCapability.Communication.Bluetooth.Core1104
1105**参数:**
1106
1107| 参数名      | 类型                          | 必填   | 说明                      |
1108| -------- | --------------------------- | ---- | ----------------------- |
1109| name     | string                      | 是    | 服务的名称。                  |
1110| option   | [SppOption](#sppoptiondeprecated)     | 是    | spp监听配置参数。              |
1111| callback | AsyncCallback&lt;number&gt; | 是    | 表示回调函数的入参,服务端Socket的id。 |
1112
1113**错误码**:
1114
1115以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1116
1117| 错误码ID | 错误信息 |
1118| -------- | ---------------------------- |
1119|201 | Permission denied.                 |
1120|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.              |
1121|801 | Capability not supported.          |
1122|2900001 | Service stopped.                         |
1123|2900003 | Bluetooth disabled.                 |
1124|2900004 | Profile not supported.                |
1125|2900099 | Operation failed.                        |
1126
1127**示例:**
1128
1129```js
1130import { BusinessError } from '@ohos.base';
1131let serverNumber = -1;
1132function serverSocket(code: BusinessError, number: number) {
1133  console.log('bluetooth error code: ' + code.code);
1134  if (code.code == 0) {
1135    console.log('bluetooth serverSocket Number: ' + number);
1136    serverNumber = number;
1137  }
1138}
1139
1140let sppOption: bluetoothManager.SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
1141try {
1142    bluetoothManager.sppListen('server1', sppOption, serverSocket);
1143} catch (err) {
1144    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1145}
1146```
1147
1148
1149## bluetoothManager.sppAccept<sup>(deprecated)</sup>
1150
1151sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void
1152
1153服务端监听socket等待客户端连接。
1154
1155> **说明:**<br/>
1156> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.sppAccept](js-apis-bluetooth-socket.md#socketsppaccept)替代。
1157
1158**系统能力**:SystemCapability.Communication.Bluetooth.Core1159
1160**参数:**
1161
1162| 参数名          | 类型                          | 必填   | 说明                      |
1163| ------------ | --------------------------- | ---- | ----------------------- |
1164| serverSocket | number                      | 是    | 服务端socket的id。           |
1165| callback     | AsyncCallback&lt;number&gt; | 是    | 表示回调函数的入参,客户端socket的id。 |
1166
1167**错误码**:
1168
1169以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1170
1171| 错误码ID | 错误信息 |
1172| -------- | ---------------------------- |
1173|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.             |
1174|801 | Capability not supported.          |
1175|2900001 | Service stopped.                         |
1176|2900003 | Bluetooth disabled.                 |
1177|2900004 | Profile not supported.                |
1178|2900099 | Operation failed.                        |
1179
1180**示例:**
1181
1182```js
1183import { BusinessError } from '@ohos.base';
1184let serverNumber = -1;
1185function serverSocket(code: BusinessError, number: number) {
1186  console.log('bluetooth error code: ' + code.code);
1187  if (code.code == 0) {
1188    console.log('bluetooth serverSocket Number: ' + number);
1189    serverNumber = number;
1190  }
1191}
1192let clientNumber = -1;
1193function acceptClientSocket(code: BusinessError, number: number) {
1194  console.log('bluetooth error code: ' + code.code);
1195  if (code.code == 0) {
1196    console.log('bluetooth clientSocket Number: ' + number);
1197    // 获取的clientNumber用作服务端后续读/写操作socket的id。
1198    clientNumber = number;
1199  }
1200}
1201try {
1202    bluetoothManager.sppAccept(serverNumber, acceptClientSocket);
1203} catch (err) {
1204    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1205}
1206```
1207
1208
1209## bluetoothManager.sppConnect<sup>(deprecated)</sup>
1210
1211sppConnect(device: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
1212
1213客户端向远端设备发起spp连接。
1214
1215> **说明:**<br/>
1216> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.sppConnect](js-apis-bluetooth-socket.md#socketsppconnect)替代。
1217
1218**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1219
1220**系统能力**:SystemCapability.Communication.Bluetooth.Core1221
1222**参数:**
1223
1224| 参数名      | 类型                          | 必填   | 说明                             |
1225| -------- | --------------------------- | ---- | ------------------------------ |
1226| device   | string                      | 是    | 对端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
1227| option   | [SppOption](#sppoptiondeprecated)     | 是    | spp客户端连接配置参数。                  |
1228| callback | AsyncCallback&lt;number&gt; | 是    | 表示回调函数的入参,客户端socket的id。        |
1229
1230**错误码**:
1231
1232以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1233
1234| 错误码ID | 错误信息 |
1235| -------- | ---------------------------- |
1236|201 | Permission denied.                 |
1237|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.               |
1238|801 | Capability not supported.          |
1239|2900001 | Service stopped.                         |
1240|2900003 | Bluetooth disabled.                 |
1241|2900004 | Profile not supported.                |
1242|2900099 | Operation failed.                        |
1243
1244**示例:**
1245
1246```js
1247import { BusinessError } from '@ohos.base';
1248
1249let clientNumber = -1;
1250function clientSocket(code: BusinessError, number: number) {
1251  if (code.code != 0 || code == null) {
1252    return;
1253  }
1254  console.log('bluetooth serverSocket Number: ' + number);
1255  // 获取的clientNumber用作客户端后续读/写操作socket的id。
1256  clientNumber = number;
1257}
1258let sppOption: bluetoothManager.SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
1259try {
1260    bluetoothManager.sppConnect('XX:XX:XX:XX:XX:XX', sppOption, clientSocket);
1261} catch (err) {
1262    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1263}
1264```
1265
1266
1267## bluetoothManager.sppCloseServerSocket<sup>(deprecated)</sup>
1268
1269sppCloseServerSocket(socket: number): void
1270
1271关闭服务端监听Socket,入参socket由sppListen接口返回。
1272
1273> **说明:**<br/>
1274> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.sppCloseServerSocket](js-apis-bluetooth-socket.md#socketsppcloseserversocket)替代。
1275
1276**系统能力**:SystemCapability.Communication.Bluetooth.Core1277
1278**参数:**
1279
1280| 参数名    | 类型     | 必填   | 说明              |
1281| ------ | ------ | ---- | --------------- |
1282| socket | number | 是    | 服务端监听socket的id。 |
1283
1284**错误码**:
1285
1286以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1287
1288| 错误码ID | 错误信息 |
1289| -------- | ---------------------------- |
1290|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.               |
1291|801 | Capability not supported.          |
1292|2900001 | Service stopped.                         |
1293|2900099 | Operation failed.                        |
1294
1295**示例:**
1296
1297```js
1298import { BusinessError } from '@ohos.base';
1299let serverNumber = -1;
1300function serverSocket(code: BusinessError, number: number) {
1301  console.log('bluetooth error code: ' + code.code);
1302  if (code.code == 0) {
1303    console.log('bluetooth serverSocket Number: ' + number);
1304    serverNumber = number;
1305  }
1306}
1307try {
1308    bluetoothManager.sppCloseServerSocket(serverNumber);
1309} catch (err) {
1310    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1311}
1312```
1313
1314
1315## bluetoothManager.sppCloseClientSocket<sup>(deprecated)</sup>
1316
1317sppCloseClientSocket(socket: number): void
1318
1319关闭客户端socket,入参socket由sppAccept或sppConnect接口获取。
1320
1321> **说明:**<br/>
1322> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.sppCloseClientSocket](js-apis-bluetooth-socket.md#socketsppcloseclientsocket)替代。
1323
1324**系统能力**:SystemCapability.Communication.Bluetooth.Core1325
1326**参数:**
1327
1328| 参数名    | 类型     | 必填   | 说明            |
1329| ------ | ------ | ---- | ------------- |
1330| socket | number | 是    | 客户端socket的id。 |
1331
1332**错误码**:
1333
1334以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1335
1336| 错误码ID | 错误信息 |
1337| -------- | ---------------------------- |
1338|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                 |
1339|801 | Capability not supported.          |
1340|2900001 | Service stopped.                         |
1341|2900099 | Operation failed.                        |
1342
1343**示例:**
1344
1345```js
1346import { BusinessError } from '@ohos.base';
1347let clientNumber = -1;
1348function clientSocket(code: BusinessError, number: number) {
1349  if (code.code != 0 || code == null) {
1350    return;
1351  }
1352  console.log('bluetooth serverSocket Number: ' + number);
1353  // 获取的clientNumber用作客户端后续读/写操作socket的id。
1354  clientNumber = number;
1355}
1356try {
1357    bluetoothManager.sppCloseClientSocket(clientNumber);
1358} catch (err) {
1359    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1360}
1361```
1362
1363
1364## bluetoothManager.sppWrite<sup>(deprecated)</sup>
1365
1366sppWrite(clientSocket: number, data: ArrayBuffer): void
1367
1368通过socket向远端发送数据,入参clientSocket由sppAccept或sppConnect接口获取。
1369
1370> **说明:**<br/>
1371> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.sppWrite](js-apis-bluetooth-socket.md#socketsppwrite)替代。
1372
1373**系统能力**:SystemCapability.Communication.Bluetooth.Core1374
1375**参数:**
1376
1377| 参数名          | 类型          | 必填   | 说明            |
1378| ------------ | ----------- | ---- | ------------- |
1379| clientSocket | number      | 是    | 客户端socket的id。 |
1380| data         | ArrayBuffer | 是    | 写入的数据。        |
1381
1382**错误码**:
1383
1384以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1385
1386| 错误码ID | 错误信息 |
1387| -------- | ---------------------------- |
1388|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.               |
1389|801 | Capability not supported.          |
1390|2901054 | IO error.                                |
1391|2900099 | Operation failed.                        |
1392
1393**示例:**
1394
1395```js
1396import { BusinessError } from '@ohos.base';
1397let clientNumber = -1;
1398function clientSocket(code: BusinessError, number: number) {
1399  if (code.code != 0 || code == null) {
1400    return;
1401  }
1402  console.log('bluetooth serverSocket Number: ' + number);
1403  // 获取的clientNumber用作客户端后续读/写操作socket的id。
1404  clientNumber = number;
1405}
1406let arrayBuffer = new ArrayBuffer(8);
1407let data = new Uint8Array(arrayBuffer);
1408data[0] = 123;
1409try {
1410    bluetoothManager.sppWrite(clientNumber, arrayBuffer);
1411} catch (err) {
1412    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1413}
1414```
1415
1416
1417## bluetoothManager.on('sppRead')<sup>(deprecated)</sup>
1418
1419on(type: 'sppRead', clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void
1420
1421订阅spp读请求事件,入参clientSocket由sppAccept或sppConnect接口获取。
1422
1423> **说明:**<br/>
1424> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.on('sppRead')](js-apis-bluetooth-socket.md#socketonsppread)替代。
1425
1426**系统能力**:SystemCapability.Communication.Bluetooth.Core1427
1428**参数:**
1429
1430| 参数名          | 类型                          | 必填   | 说明                         |
1431| ------------ | --------------------------- | ---- | -------------------------- |
1432| type         | string                      | 是    | 填写"sppRead"字符串,表示spp读请求事件。 |
1433| clientSocket | number                      | 是    | 客户端socket的id。              |
1434| callback     | Callback&lt;ArrayBuffer&gt; | 是    | 表示回调函数的入参,读取到的数据。          |
1435
1436**错误码**:
1437
1438以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1439
1440| 错误码ID | 错误信息 |
1441| -------- | ---------------------------- |
1442|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                |
1443|801 | Capability not supported.          |
1444|2901054 | IO error.                                |
1445|2900099 | Operation failed.                        |
1446
1447**示例:**
1448
1449```js
1450import { BusinessError } from '@ohos.base';
1451let clientNumber = -1;
1452function clientSocket(code: BusinessError, number: number) {
1453  if (code.code != 0 || code == null) {
1454    return;
1455  }
1456  console.log('bluetooth serverSocket Number: ' + number);
1457  // 获取的clientNumber用作客户端后续读/写操作socket的id。
1458  clientNumber = number;
1459}
1460function dataRead(dataBuffer: ArrayBuffer) {
1461  let data = new Uint8Array(dataBuffer);
1462  console.log('bluetooth data is: ' + data[0]);
1463}
1464try {
1465    bluetoothManager.on('sppRead', clientNumber, dataRead);
1466} catch (err) {
1467    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1468}
1469```
1470
1471
1472## bluetoothManager.off('sppRead')<sup>(deprecated)</sup>
1473
1474off(type: 'sppRead', clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void
1475
1476取消订阅spp读请求事件,入参clientSocket由sppAccept或sppConnect接口获取。
1477
1478> **说明:**<br/>
1479> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.off('sppRead')](js-apis-bluetooth-socket.md#socketoffsppread)替代。
1480
1481**系统能力**:SystemCapability.Communication.Bluetooth.Core1482
1483**参数:**
1484
1485| 参数名          | 类型                          | 必填   | 说明                                       |
1486| ------------ | --------------------------- | ---- | ---------------------------------------- |
1487| type         | string                      | 是    | 填写"sppRead"字符串,表示spp读请求事件。               |
1488| clientSocket | number                      | 是    | 客户端Socket的id。                            |
1489| callback     | Callback&lt;ArrayBuffer&gt; | 否    | 表示取消订阅spp读请求事件上报。不填该参数则取消订阅该type对应的所有回调。 |
1490
1491**错误码**:
1492
1493以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1494
1495| 错误码ID | 错误信息 |
1496| -------- | ---------------------------- |
1497|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.              |
1498|801 | Capability not supported.          |
1499
1500**示例:**
1501
1502```js
1503import { BusinessError } from '@ohos.base';
1504let clientNumber = -1;
1505function clientSocket(code: BusinessError, number: number) {
1506  if (code.code != 0 || code == null) {
1507    return;
1508  }
1509  console.log('bluetooth serverSocket Number: ' + number);
1510  // 获取的clientNumber用作客户端后续读/写操作socket的id。
1511  clientNumber = number;
1512}
1513try {
1514    bluetoothManager.off('sppRead', clientNumber);
1515} catch (err) {
1516    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1517}
1518```
1519
1520## bluetoothManager.getProfileInstance<sup>(deprecated)</sup>
1521
1522getProfileInstance(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile | PanProfile
1523
1524通过ProfileId,获取profile的对象实例,API9新增了HidHostProfile,PanProfile。
1525
1526**系统能力**:SystemCapability.Communication.Bluetooth.Core1527
1528**参数:**
1529
1530| 参数名       | 类型        | 必填   | 说明                                    |
1531| --------- | --------- | ---- | ------------------------------------- |
1532| profileId | [ProfileId](#profileiddeprecated) | 是    | 表示profile的枚举值,例如:PROFILE_A2DP_SOURCE。 |
1533
1534**返回值:**
1535
1536| 类型                                                         | 说明                                                         |
1537| ------------------------------------------------------------ | ------------------------------------------------------------ |
1538| [A2dpSourceProfile](#a2dpsourceprofile)或 [HandsFreeAudioGatewayProfile](#handsfreeaudiogatewayprofiledeprecated)或[HidHostProfile](#hidhostprofiledeprecated)或[PanProfile](#panprofile) | 对应的profile的对象实例,当前支持A2dpSourceProfile/HandsFreeAudioGatewayProfile/HidHostProfile/PanProfile。 |
1539
1540**错误码**:
1541
1542以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1543
1544| 错误码ID | 错误信息 |
1545| -------- | ---------------------------- |
1546|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.           |
1547|801 | Capability not supported.          |
1548
1549**示例:**
1550
1551```js
1552import { BusinessError } from '@ohos.base';
1553try {
1554    let hidHost: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST);
1555} catch (err) {
1556    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1557}
1558```
1559
1560
1561## BLE
1562
1563BLE模块提供了对蓝牙操作和管理的方法。
1564
1565### createGattServer<sup>(deprecated)</sup>
1566
1567createGattServer(): GattServer
1568
1569创建一个可使用的GattServer实例。
1570
1571> **说明:**<br/>
1572> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.createGattServer](js-apis-bluetooth-ble.md#blecreategattserver)替代。
1573
1574**系统能力**:SystemCapability.Communication.Bluetooth.Core1575
1576**返回值:**
1577
1578| 类型                        | 说明                                   |
1579| ------------------------- | ------------------------------------ |
1580| [GattServer](#gattserver) | server端类,使用server端方法之前需要创建该类的实例进行操作。 |
1581
1582**示例:**
1583
1584```js
1585let gattServer: bluetoothManager.GattServer  = bluetoothManager.BLE.createGattServer();
1586```
1587
1588
1589### createGattClientDevice<sup>(deprecated)</sup>
1590
1591createGattClientDevice(deviceId: string): GattClientDevice
1592
1593创建一个可使用的GattClientDevice实例。
1594
1595> **说明:**<br/>
1596> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.createGattClientDevice](js-apis-bluetooth-ble.md#blecreategattclientdevice)替代。
1597
1598**系统能力**:SystemCapability.Communication.Bluetooth.Core1599
1600**参数:**
1601
1602| 参数名      | 类型     | 必填   | 说明                                   |
1603| -------- | ------ | ---- | ------------------------------------ |
1604| deviceId | string | 是    | 对端设备地址,&nbsp;例如:"XX:XX:XX:XX:XX:XX"。 |
1605
1606**返回值:**
1607
1608| 类型                                    | 说明                                   |
1609| ------------------------------------- | ------------------------------------ |
1610| [GattClientDevice](#gattclientdevice) | client端类,使用client端方法之前需要创建该类的实例进行操作。 |
1611
1612**错误码**:
1613
1614以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1615
1616| 错误码ID | 错误信息 |
1617| -------- | ---------------------------- |
1618|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
1619|801 | Capability not supported.          |
1620
1621**示例:**
1622
1623```js
1624import { BusinessError } from '@ohos.base';
1625try {
1626    let device: bluetoothManager.GattClientDevice = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
1627} catch (err) {
1628    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1629}
1630```
1631
1632
1633### getConnectedBLEDevices<sup>(deprecated)</sup>
1634
1635getConnectedBLEDevices(): Array&lt;string&gt;
1636
1637获取和当前设备连接的BLE设备。
1638
1639> **说明:**<br/>
1640> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.getConnectedBLEDevices](js-apis-bluetooth-ble.md#blegetconnectedbledevices)替代。
1641
1642**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1643
1644**系统能力**:SystemCapability.Communication.Bluetooth.Core1645
1646**返回值:**
1647
1648| 类型                  | 说明                  |
1649| ------------------- | ------------------- |
1650| Array&lt;string&gt; | 返回当前设备作为Server端时连接BLE设备地址集合。 |
1651
1652**错误码**:
1653
1654以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1655
1656| 错误码ID | 错误信息 |
1657| -------- | ---------------------------- |
1658|201 | Permission denied.                 |
1659|801 | Capability not supported.          |
1660|2900001 | Service stopped.                         |
1661|2900003 | Bluetooth disabled.                 |
1662|2900099 | Operation failed.                        |
1663
1664**示例:**
1665
1666```js
1667import { BusinessError } from '@ohos.base';
1668try {
1669    let result: Array<string>  = bluetoothManager.BLE.getConnectedBLEDevices();
1670} catch (err) {
1671    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1672}
1673```
1674
1675
1676### startBLEScan<sup>(deprecated)</sup>
1677
1678startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
1679
1680发起BLE扫描流程。
1681
1682> **说明:**<br/>
1683> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.startBLEScan](js-apis-bluetooth-ble.md#blestartblescan)替代。
1684
1685**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1686
1687**系统能力**:SystemCapability.Communication.Bluetooth.Core1688
1689**参数:**
1690
1691| 参数名     | 类型                                     | 必填   | 说明                                  |
1692| ------- | -------------------------------------- | ---- | ----------------------------------- |
1693| filters | Array&lt;[ScanFilter](#scanfilterdeprecated)&gt; | 是    | 表示扫描结果过滤策略集合,如果不使用过滤的方式,该参数设置为null。 |
1694| options | [ScanOptions](#scanoptionsdeprecated)            | 否    | 表示扫描的参数配置,可选参数。                     |
1695
1696**错误码**:
1697
1698以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1699
1700| 错误码ID | 错误信息 |
1701| -------- | ---------------------------- |
1702|201 | Permission denied.                 |
1703|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
1704|801 | Capability not supported.          |
1705|2900001 | Service stopped.                         |
1706|2900003 | Bluetooth disabled.                 |
1707|2900099 | Operation failed.                        |
1708
1709**示例:**
1710
1711```js
1712import { BusinessError } from '@ohos.base';
1713function onReceiveEvent(data: Array<bluetoothManager.ScanResult>) {
1714    console.info('BLE scan device find result = '+ JSON.stringify(data));
1715}
1716try {
1717    bluetoothManager.BLE.on("BLEDeviceFind", onReceiveEvent);
1718    let scanfilter: bluetoothManager.ScanFilter = {
1719        deviceId:"XX:XX:XX:XX:XX:XX",
1720        name:"test",
1721        serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
1722    };
1723    let scanoptions: bluetoothManager.ScanOptions = {
1724        interval: 500,
1725        dutyMode: bluetoothManager.ScanDuty.SCAN_MODE_LOW_POWER,
1726        matchMode: bluetoothManager.MatchMode.MATCH_MODE_AGGRESSIVE,
1727    }
1728    bluetoothManager.BLE.startBLEScan([scanfilter], scanoptions);
1729} catch (err) {
1730    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1731}
1732```
1733
1734
1735### stopBLEScan<sup>(deprecated)</sup>
1736
1737stopBLEScan(): void
1738
1739停止BLE扫描流程。
1740
1741> **说明:**<br/>
1742> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.startBLEScan](js-apis-bluetooth-ble.md#blestopblescan)替代。
1743
1744**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1745
1746**系统能力**:SystemCapability.Communication.Bluetooth.Core1747
1748**错误码**:
1749
1750以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1751
1752| 错误码ID | 错误信息 |
1753| -------- | ---------------------------- |
1754|201 | Permission denied.                 |
1755|801 | Capability not supported.          |
1756|2900001 | Service stopped.                         |
1757|2900003 | Bluetooth disabled.                 |
1758|2900099 | Operation failed.                        |
1759
1760**示例:**
1761
1762```js
1763import { BusinessError } from '@ohos.base';
1764try {
1765    bluetoothManager.BLE.stopBLEScan();
1766} catch (err) {
1767    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1768}
1769```
1770
1771
1772### on('BLEDeviceFind')<sup>(deprecated)</sup>
1773
1774on(type: 'BLEDeviceFind', callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
1775
1776订阅BLE设备发现上报事件。
1777
1778> **说明:**<br/>
1779> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.on('BLEDeviceFind')](js-apis-bluetooth-ble.md#bleonbledevicefind)替代。
1780
1781**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1782
1783**系统能力**:SystemCapability.Communication.Bluetooth.Core1784
1785**参数:**
1786
1787| 参数名      | 类型                                       | 必填   | 说明                                  |
1788| -------- | ---------------------------------------- | ---- | ----------------------------------- |
1789| type     | string                                   | 是    | 填写"BLEDeviceFind"字符串,表示BLE设备发现事件。   |
1790| callback | Callback&lt;Array&lt;[ScanResult](#scanresultdeprecated)&gt;&gt; | 是    | 表示回调函数的入参,发现的设备集合。回调函数由用户创建通过该接口注册。 |
1791
1792**错误码**:
1793
1794以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1795
1796| 错误码ID | 错误信息 |
1797| -------- | ---------------------------- |
1798|201 | Permission denied.                 |
1799|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
1800|801 | Capability not supported.          |
1801|2900099 | Operation failed.                        |
1802
1803**示例:**
1804
1805```js
1806import { BusinessError } from '@ohos.base';
1807function onReceiveEvent(data: Array<bluetoothManager.ScanResult>) {
1808    console.info('bluetooth device find = '+ JSON.stringify(data));
1809}
1810try {
1811    bluetoothManager.BLE.on('BLEDeviceFind', onReceiveEvent);
1812} catch (err) {
1813    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1814}
1815```
1816
1817
1818### off('BLEDeviceFind')<sup>(deprecated)</sup>
1819
1820off(type: 'BLEDeviceFind', callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
1821
1822取消订阅BLE设备发现上报事件。
1823
1824> **说明:**<br/>
1825> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.off('BLEDeviceFind')](js-apis-bluetooth-ble.md#bleoffbledevicefind)替代。
1826
1827**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1828
1829**系统能力**:SystemCapability.Communication.Bluetooth.Core1830
1831**参数:**
1832
1833| 参数名      | 类型                                       | 必填   | 说明                                       |
1834| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1835| type     | string                                   | 是    | 填写"BLEDeviceFind"字符串,表示BLE设备发现事件。        |
1836| callback | Callback&lt;Array&lt;[ScanResult](#scanresultdeprecated)&gt;&gt; | 否    | 表示取消订阅BLE设备发现事件上报。不填该参数则取消订阅该type对应的所有回调。 |
1837
1838**错误码**:
1839
1840以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1841
1842| 错误码ID | 错误信息 |
1843| -------- | ---------------------------- |
1844|201 | Permission denied.                 |
1845|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
1846|801 | Capability not supported.          |
1847|2900099 | Operation failed.                        |
1848
1849**示例:**
1850
1851```js
1852import { BusinessError } from '@ohos.base';
1853function onReceiveEvent(data: Array<bluetoothManager.ScanResult>) {
1854    console.info('bluetooth device find = '+ JSON.stringify(data));
1855}
1856try {
1857    bluetoothManager.BLE.on('BLEDeviceFind', onReceiveEvent);
1858    bluetoothManager.BLE.off('BLEDeviceFind', onReceiveEvent);
1859} catch (err) {
1860    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1861}
1862```
1863
1864
1865## BaseProfile
1866
1867profile基类。
1868
1869
1870### getConnectionDevices<sup>(deprecated)</sup>
1871
1872getConnectionDevices(): Array&lt;string&gt;
1873
1874获取已连接设备列表。
1875
1876> **说明:**<br/>
1877> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.getConnectedDevices](js-apis-bluetooth-baseProfile.md#baseprofilegetconnecteddevices)替代。
1878
1879**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1880
1881**系统能力**:SystemCapability.Communication.Bluetooth.Core1882
1883**返回值:**
1884
1885| 类型                  | 说明            |
1886| ------------------- | ------------- |
1887| Array&lt;string&gt; | 返回已连接设备的地址列表。 |
1888
1889**错误码**:
1890
1891以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1892
1893| 错误码ID | 错误信息 |
1894| -------- | ---------------------------- |
1895|201 | Permission denied.                 |
1896|801 | Capability not supported.          |
1897|2900001 | Service stopped.                         |
1898|2900003 | Bluetooth disabled.                 |
1899|2900004 | Profile not supported.                |
1900|2900099 | Operation failed.                        |
1901
1902**示例:**
1903
1904```js
1905import { BusinessError } from '@ohos.base';
1906try {
1907    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
1908    let retArray: Array<string> = a2dpSrc.getConnectionDevices();
1909} catch (err) {
1910    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1911}
1912```
1913
1914### getDeviceState<sup>(deprecated)</sup>
1915
1916getDeviceState(device: string): ProfileConnectionState
1917
1918获取设备profile的连接状态。
1919
1920> **说明:**<br/>
1921> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.getConnectionState](js-apis-bluetooth-baseProfile.md#baseprofilegetconnectionstate)替代。
1922
1923**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1924
1925**系统能力**:SystemCapability.Communication.Bluetooth.Core1926
1927**参数:**
1928
1929| 参数名    | 类型     | 必填   | 说明      |
1930| ------ | ------ | ---- | ------- |
1931| device | string | 是    | 远端设备地址。 |
1932
1933**返回值:**
1934
1935| 类型                                              | 说明                    |
1936| ------------------------------------------------- | ----------------------- |
1937| [ProfileConnectionState](#profileconnectionstatedeprecated) | 返回profile的连接状态。 |
1938
1939**错误码**:
1940
1941以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1942
1943| 错误码ID | 错误信息 |
1944| -------- | ---------------------------- |
1945|201 | Permission denied.                 |
1946|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
1947|801 | Capability not supported.          |
1948|2900001 | Service stopped.                         |
1949|2900003 | Bluetooth disabled.                 |
1950|2900004 | Profile not supported.                |
1951|2900099 | Operation failed.                        |
1952
1953**示例:**
1954
1955```js
1956import { BusinessError } from '@ohos.base';
1957try {
1958    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
1959    let ret: bluetoothManager.ProfileConnectionState = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX');
1960} catch (err) {
1961    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
1962}
1963```
1964
1965
1966## A2dpSourceProfile
1967
1968使用A2dpSourceProfile方法之前需要创建该类的实例进行操作,通过getProfile()方法构造此实例。
1969
1970> **说明:**<br/>
1971> 从API version 9开始支持,从API version 10开始废弃。建议使用[a2dp.A2dpSourceProfile](js-apis-bluetooth-a2dp.md#a2dpsourceprofile)替代。
1972
1973
1974### connect<sup>(deprecated)</sup>
1975
1976connect(device: string): void
1977
1978发起设备的A2dp服务连接请求。
1979
1980> **说明:**<br/>
1981> 从API version 9开始支持,从API version 10开始废弃。替代接口仅向系统应用开放。
1982
1983**需要权限**:ohos.permission.ACCESS_BLUETOOTH
1984
1985**系统能力**:SystemCapability.Communication.Bluetooth.Core1986
1987**参数:**
1988
1989| 参数名    | 类型     | 必填   | 说明      |
1990| ------ | ------ | ---- | ------- |
1991| device | string | 是    | 远端设备地址。 |
1992
1993**错误码**:
1994
1995以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
1996
1997| 错误码ID | 错误信息 |
1998| -------- | ---------------------------- |
1999|201 | Permission denied.                 |
2000|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2001|801 | Capability not supported.          |
2002|2900001 | Service stopped.                         |
2003|2900003 | Bluetooth disabled.                 |
2004|2900004 | Profile not supported.                |
2005|2900099 | Operation failed.                        |
2006
2007**示例:**
2008
2009```js
2010import { BusinessError } from '@ohos.base';
2011try {
2012    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
2013    a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
2014} catch (err) {
2015    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2016}
2017```
2018
2019
2020### disconnect<sup>(deprecated)</sup>
2021
2022disconnect(device: string): void
2023
2024断开设备的a2dp服务连接。
2025
2026> **说明:**<br/>
2027> 从API version 9开始支持,从API version 10开始废弃。替代接口仅向系统应用开放。
2028
2029**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2030
2031**系统能力**:SystemCapability.Communication.Bluetooth.Core2032
2033**参数:**
2034
2035| 参数名    | 类型     | 必填   | 说明      |
2036| ------ | ------ | ---- | ------- |
2037| device | string | 是    | 远端设备地址。 |
2038
2039**错误码**:
2040
2041以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2042
2043| 错误码ID | 错误信息 |
2044| -------- | ---------------------------- |
2045|201 | Permission denied.                 |
2046|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2047|801 | Capability not supported.          |
2048|2900001 | Service stopped.                         |
2049|2900003 | Bluetooth disabled.                 |
2050|2900004 | Profile not supported.                |
2051|2900099 | Operation failed.                        |
2052
2053**示例:**
2054
2055```js
2056import { BusinessError } from '@ohos.base';
2057try {
2058    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
2059    a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
2060} catch (err) {
2061    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2062}
2063```
2064
2065
2066### on('connectionStateChange')<sup>(deprecated)</sup>
2067
2068on(type: 'connectionStateChange', callback: Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt;): void
2069
2070订阅a2dp连接状态变化事件。
2071
2072> **说明:**<br/>
2073> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange)替代。
2074
2075**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2076
2077**系统能力**:SystemCapability.Communication.Bluetooth.Core2078
2079**参数:**
2080
2081| 参数名      | 类型                                       | 必填   | 说明                                       |
2082| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2083| type     | string                                   | 是    | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
2084| callback | Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt; | 是    | 表示回调函数的入参。                               |
2085
2086**返回值:**
2087
20882089
2090**错误码**:
2091
2092以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2093
2094| 错误码ID | 错误信息 |
2095| -------- | ---------------------------- |
2096|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2097|801 | Capability not supported.          |
2098
2099**示例:**
2100
2101```js
2102import { BusinessError } from '@ohos.base';
2103function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2104    console.info('a2dp state = '+ JSON.stringify(data));
2105}
2106try {
2107let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
2108a2dpSrc.on('connectionStateChange', onReceiveEvent);
2109} catch (err) {
2110    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
2111}
2112```
2113
2114
2115### off('connectionStateChange')<sup>(deprecated)</sup>
2116
2117off(type: 'connectionStateChange', callback?: Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt;): void
2118
2119取消订阅a2dp连接状态变化事件。
2120
2121> **说明:**<br/>
2122> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange)替代。
2123
2124**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2125
2126**系统能力**:SystemCapability.Communication.Bluetooth.Core2127
2128**参数:**
2129
2130| 参数名      | 类型                                       | 必填   | 说明                                       |
2131| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2132| type     | string                                   | 是    | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
2133| callback | Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt; | 否    | 表示回调函数的入参。                               |
2134
2135**返回值:**
2136
21372138
2139**错误码**:
2140
2141以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2142
2143| 错误码ID | 错误信息 |
2144| -------- | ---------------------------- |
2145|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2146|801 | Capability not supported.          |
2147
2148**示例:**
2149
2150```js
2151import { BusinessError } from '@ohos.base';
2152function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2153    console.info('a2dp state = '+ JSON.stringify(data));
2154}
2155try {
2156let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
2157a2dpSrc.on('connectionStateChange', onReceiveEvent);
2158a2dpSrc.off('connectionStateChange', onReceiveEvent);
2159} catch (err) {
2160    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
2161}
2162```
2163
2164
2165### getPlayingState<sup>(deprecated)</sup>
2166
2167getPlayingState(device: string): PlayingState
2168
2169获取设备的播放状态。
2170
2171> **说明:**<br/>
2172> 从API version 9开始支持,从API version 10开始废弃。建议使用[a2dp.A2dpSourceProfile#getPlayingState](js-apis-bluetooth-a2dp.md#getPlayingState)替代。
2173
2174**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2175
2176**系统能力**:SystemCapability.Communication.Bluetooth.Core2177
2178**参数:**
2179
2180| 参数名    | 类型     | 必填   | 说明      |
2181| ------ | ------ | ---- | ------- |
2182| device | string | 是    | 远端设备地址。 |
2183
2184**返回值:**
2185
2186| 类型                            | 说明         |
2187| ----------------------------- | ---------- |
2188| [PlayingState](#playingstatedeprecated) | 远端设备的播放状态。 |
2189
2190**错误码**:
2191
2192以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2193
2194| 错误码ID | 错误信息 |
2195| -------- | ---------------------------- |
2196|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2197|801 | Capability not supported.          |
2198|2900001 | Service stopped.                         |
2199|2900003 | Bluetooth disabled.                 |
2200|2900004 | Profile not supported.                |
2201|2900099 | Operation failed.                        |
2202
2203**示例:**
2204
2205```js
2206import { BusinessError } from '@ohos.base';
2207try {
2208    let a2dpSrc: bluetoothManager.A2dpSourceProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
2209    let state: bluetoothManager.PlayingState  = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
2210} catch (err) {
2211    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2212}
2213```
2214
2215
2216## HandsFreeAudioGatewayProfile<sup>(deprecated)</sup>
2217
2218使用HandsFreeAudioGatewayProfile方法之前需要创建该类的实例进行操作,通过getProfile()方法构造此实例。
2219
2220> **说明:**<br/>
2221> 从API version 9开始支持,从API version 10开始废弃。建议使用[hfp.HandsFreeAudioGatewayProfile](js-apis-bluetooth-hfp.md#HandsFreeAudioGatewayProfile)替代。
2222
2223
2224### connect
2225
2226connect(device: string): void
2227
2228连接设备的HFP服务。
2229
2230> **说明:**<br/>
2231> 从API version 9开始支持,从API version 10开始废弃。替代接口仅向系统应用开放。
2232
2233**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2234
2235**系统能力**:SystemCapability.Communication.Bluetooth.Core2236
2237**参数:**
2238
2239| 参数名    | 类型     | 必填   | 说明      |
2240| ------ | ------ | ---- | ------- |
2241| device | string | 是    | 远端设备地址。 |
2242
2243**错误码**:
2244
2245以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2246
2247| 错误码ID | 错误信息 |
2248| -------- | ---------------------------- |
2249|201 | Permission denied.                 |
2250|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2251|801 | Capability not supported.          |
2252|2900001 | Service stopped.                         |
2253|2900003 | Bluetooth disabled.                 |
2254|2900004 | Profile not supported.                |
2255|2900099 | Operation failed.                        |
2256
2257**示例:**
2258
2259```js
2260import { BusinessError } from '@ohos.base';
2261try {
2262    let hfpAg: bluetoothManager.HandsFreeAudioGatewayProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as bluetoothManager.HandsFreeAudioGatewayProfile;
2263    hfpAg.connect('XX:XX:XX:XX:XX:XX');
2264} catch (err) {
2265    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2266}
2267```
2268
2269
2270### disconnect<sup>(deprecated)</sup>
2271
2272disconnect(device: string): void
2273
2274断开连接设备的HFP服务。
2275
2276> **说明:**<br/>
2277> 从API version 9开始支持,从API version 10开始废弃。替代接口仅向系统应用开放。
2278
2279**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2280
2281**系统能力**:SystemCapability.Communication.Bluetooth.Core2282
2283**参数:**
2284
2285| 参数名    | 类型     | 必填   | 说明      |
2286| ------ | ------ | ---- | ------- |
2287| device | string | 是    | 远端设备地址。 |
2288
2289**错误码**:
2290
2291以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2292
2293| 错误码ID | 错误信息 |
2294| -------- | ---------------------------- |
2295|201 | Permission denied.                 |
2296|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2297|801 | Capability not supported.          |
2298|2900001 | Service stopped.                         |
2299|2900003 | Bluetooth disabled.                 |
2300|2900004 | Profile not supported.                |
2301|2900099 | Operation failed.                        |
2302
2303**示例:**
2304
2305```js
2306import { BusinessError } from '@ohos.base';
2307try {
2308    let hfpAg: bluetoothManager.HandsFreeAudioGatewayProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as bluetoothManager.HandsFreeAudioGatewayProfile;
2309    hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
2310} catch (err) {
2311    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2312}
2313```
2314
2315
2316### on('connectionStateChange')<sup>(deprecated)</sup>
2317
2318on(type: 'connectionStateChange', callback: Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt;): void
2319
2320订阅HFP连接状态变化事件。
2321
2322> **说明:**<br/>
2323> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange)替代。
2324
2325**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2326
2327**系统能力**:SystemCapability.Communication.Bluetooth.Core2328
2329**参数:**
2330
2331| 参数名      | 类型                                       | 必填   | 说明                                       |
2332| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2333| type     | string                                   | 是    | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
2334| callback | Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt; | 是    | 表示回调函数的入参。                               |
2335
2336**错误码**:
2337
2338以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2339
2340| 错误码ID | 错误信息 |
2341| -------- | ---------------------------- |
2342|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2343|801 | Capability not supported.          |
2344
2345**示例:**
2346
2347```js
2348import { BusinessError } from '@ohos.base';
2349function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2350    console.info('hfp state = '+ JSON.stringify(data));
2351}
2352try {
2353let hfpAg: bluetoothManager.HandsFreeAudioGatewayProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
2354  bluetoothManager.HandsFreeAudioGatewayProfile;
2355hfpAg.on('connectionStateChange', onReceiveEvent);
2356} catch (err) {
2357    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2358}
2359```
2360
2361
2362### off('connectionStateChange')<sup>(deprecated)</sup>
2363
2364off(type: 'connectionStateChange', callback?: Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt;): void
2365
2366取消订阅HFP连接状态变化事件。
2367
2368> **说明:**<br/>
2369> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange)替代。
2370
2371**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2372
2373**系统能力**:SystemCapability.Communication.Bluetooth.Core2374
2375**参数:**
2376
2377| 参数名      | 类型                                       | 必填   | 说明                                       |
2378| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2379| type     | string                                   | 是    | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
2380| callback | Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt; | 否    | 表示回调函数的入参。                               |
2381
2382**错误码**:
2383
2384以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2385
2386| 错误码ID | 错误信息 |
2387| -------- | ---------------------------- |
2388|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2389|801 | Capability not supported.          |
2390**示例:**
2391
2392```js
2393import { BusinessError } from '@ohos.base';
2394function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2395    console.info('hfp state = '+ JSON.stringify(data));
2396}
2397try {
2398let hfpAg: bluetoothManager.HandsFreeAudioGatewayProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
2399  bluetoothManager.HandsFreeAudioGatewayProfile;
2400hfpAg.on('connectionStateChange', onReceiveEvent);
2401hfpAg.off('connectionStateChange', onReceiveEvent);
2402} catch (err) {
2403    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2404}
2405```
2406
2407
2408## HidHostProfile<sup>(deprecated)</sup>
2409
2410使用HidHostProfile方法之前需要创建该类的实例进行操作,通过getProfile()方法构造此实例。
2411
2412### on('connectionStateChange')<sup>(deprecated)</sup>
2413
2414on(type: 'connectionStateChange', callback: Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt;): void
2415
2416订阅HidHost连接状态变化事件。
2417
2418> **说明:**<br/>
2419> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange)替代。
2420
2421**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2422
2423**系统能力**:SystemCapability.Communication.Bluetooth.Core2424
2425**参数:**
2426
2427| 参数名      | 类型                                       | 必填   | 说明                                       |
2428| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2429| type     | string                                   | 是    | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
2430| callback | Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt; | 是    | 表示回调函数的入参。                               |
2431
2432**错误码**:
2433
2434以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2435
2436| 错误码ID | 错误信息 |
2437| -------- | ---------------------------- |
2438|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2439|801 | Capability not supported.          |
2440
2441**示例:**
2442
2443```js
2444import { BusinessError } from '@ohos.base';
2445function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2446    console.info('hidHost state = '+ JSON.stringify(data));
2447}
2448try {
2449let hidHost: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
2450hidHost.on('connectionStateChange', onReceiveEvent);
2451} catch (err) {
2452    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2453}
2454```
2455
2456
2457### off('connectionStateChange')<sup>(deprecated)</sup>
2458
2459off(type: 'connectionStateChange', callback?: Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt;): void
2460
2461取消订阅HidHost连接状态变化事件。
2462
2463> **说明:**<br/>
2464> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange)替代。
2465
2466**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2467
2468**系统能力**:SystemCapability.Communication.Bluetooth.Core2469
2470**参数:**
2471
2472| 参数名   | 类型                                                  | 必填 | 说明                                                      |
2473| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
2474| type     | string                                                | 是   | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
2475| callback | Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt; | 否   | 表示回调函数的入参。                                      |
2476
2477**错误码**:
2478
2479以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2480
2481| 错误码ID | 错误信息 |
2482| -------- | ---------------------------- |
2483|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2484|801 | Capability not supported.          |
2485
2486**示例:**
2487
2488```js
2489import { BusinessError } from '@ohos.base';
2490function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2491    console.info('hidHost state = '+ JSON.stringify(data));
2492}
2493try {
2494let hidHost: bluetoothManager.HidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
2495hidHost.on('connectionStateChange', onReceiveEvent);
2496hidHost.off('connectionStateChange', onReceiveEvent);
2497} catch (err) {
2498    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2499}
2500```
2501
2502
2503## PanProfile
2504
2505使用PanProfile方法之前需要创建该类的实例进行操作,通过getProfile()方法构造此实例。
2506
2507> **说明:**<br/>
2508> 从API version 9开始支持,从API version 10开始废弃。建议使用[pan.PanProfile](js-apis-bluetooth-pan.md#panprofile)替代。
2509
2510
2511
2512
2513### on('connectionStateChange')<sup>(deprecated)</sup>
2514
2515on(type: 'connectionStateChange', callback: Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt;): void
2516
2517订阅Pan连接状态变化事件。
2518
2519> **说明:**<br/>
2520> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.on('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileonconnectionstatechange)替代。
2521
2522**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2523
2524**系统能力**:SystemCapability.Communication.Bluetooth.Core2525
2526**参数:**
2527
2528| 参数名      | 类型                                       | 必填   | 说明                                       |
2529| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
2530| type     | string                                   | 是    | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
2531| callback | Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt; | 是    | 表示回调函数的入参。                               |
2532
2533**错误码**:
2534
2535以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2536
2537| 错误码ID | 错误信息 |
2538| -------- | ---------------------------- |
2539|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2540|801 | Capability not supported.          |
2541
2542**示例:**
2543
2544```js
2545import { BusinessError } from '@ohos.base';
2546function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2547    console.info('pan state = '+ JSON.stringify(data));
2548}
2549try {
2550let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
2551panProfile.on('connectionStateChange', onReceiveEvent);
2552} catch (err) {
2553    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2554}
2555```
2556
2557
2558### off('connectionStateChange')<sup>(deprecated)</sup>
2559
2560off(type: 'connectionStateChange', callback?: Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt;): void
2561
2562取消订阅Pan连接状态变化事件。
2563
2564> **说明:**<br/>
2565> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.off('connectionStateChange')](js-apis-bluetooth-baseProfile.md#baseprofileoffconnectionstatechange)替代。
2566
2567**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2568
2569**系统能力**:SystemCapability.Communication.Bluetooth.Core2570
2571**参数:**
2572
2573| 参数名   | 类型                                                  | 必填 | 说明                                                      |
2574| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
2575| type     | string                                                | 是   | 填写"connectionStateChange"字符串,表示连接状态变化事件。 |
2576| callback | Callback&lt;[StateChangeParam](#statechangeparamdeprecated)&gt; | 否   | 表示回调函数的入参。                                      |
2577
2578**错误码**:
2579
2580以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2581
2582| 错误码ID | 错误信息 |
2583| -------- | ---------------------------- |
2584|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2585|801 | Capability not supported.          |
2586
2587**示例:**
2588
2589```js
2590import { BusinessError } from '@ohos.base';
2591function onReceiveEvent(data: bluetoothManager.StateChangeParam) {
2592    console.info('pan state = '+ JSON.stringify(data));
2593}
2594try {
2595let panProfile: bluetoothManager.PanProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
2596panProfile.on('connectionStateChange', onReceiveEvent);
2597panProfile.off('connectionStateChange', onReceiveEvent);
2598} catch (err) {
2599    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2600}
2601```
2602
2603
2604## GattServer
2605
2606server端类,使用server端方法之前需要创建该类的实例进行操作,通过createGattServer()方法构造此实例。
2607
2608> **说明:**<br/>
2609> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer](js-apis-bluetooth-ble.md#GattServer)替代。
2610
2611
2612### startAdvertising<sup>(deprecated)</sup>
2613
2614startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void
2615
2616开始发送BLE广播。
2617
2618> **说明:**<br/>
2619> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.startAdvertising](js-apis-bluetooth-ble.md#blestartadvertising)替代。
2620
2621**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2622
2623**系统能力**:SystemCapability.Communication.Bluetooth.Core2624
2625**参数:**
2626
2627| 参数名         | 类型                                    | 必填   | 说明             |
2628| ----------- | ------------------------------------- | ---- | -------------- |
2629| setting     | [AdvertiseSetting](#advertisesettingdeprecated) | 是    | BLE广播的相关参数。    |
2630| advData     | [AdvertiseData](#advertisedatadeprecated)       | 是    | BLE广播包内容。      |
2631| advResponse | [AdvertiseData](#advertisedatadeprecated)       | 否    | BLE回复扫描请求回复响应。 |
2632
2633**错误码**:
2634
2635以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2636
2637| 错误码ID | 错误信息 |
2638| -------- | ---------------------------- |
2639|201 | Permission denied.                 |
2640|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2641|801 | Capability not supported.          |
2642|2900001 | Service stopped.                         |
2643|2900003 | Bluetooth disabled.                 |
2644|2900099 | Operation failed.                        |
2645
2646**示例:**
2647
2648```js
2649import { BusinessError } from '@ohos.base';
2650let manufactureValueBuffer = new Uint8Array(4);
2651manufactureValueBuffer[0] = 1;
2652manufactureValueBuffer[1] = 2;
2653manufactureValueBuffer[2] = 3;
2654manufactureValueBuffer[3] = 4;
2655
2656let serviceValueBuffer = new Uint8Array(4);
2657serviceValueBuffer[0] = 4;
2658serviceValueBuffer[1] = 6;
2659serviceValueBuffer[2] = 7;
2660serviceValueBuffer[3] = 8;
2661console.info('manufactureValueBuffer = '+ JSON.stringify(manufactureValueBuffer));
2662console.info('serviceValueBuffer = '+ JSON.stringify(serviceValueBuffer));
2663let gattServer = bluetoothManager.BLE.createGattServer();
2664try {
2665    let setting: bluetoothManager.AdvertiseSetting = {
2666        interval:150,
2667        txPower:0,
2668        connectable:true,
2669    };
2670    let manufactureDataUnit: bluetoothManager.ManufactureData = {
2671        manufactureId:4567,
2672        manufactureValue:manufactureValueBuffer.buffer
2673    };
2674    let serviceDataUnit: bluetoothManager.ServiceData = {
2675        serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
2676        serviceValue:serviceValueBuffer.buffer
2677    };
2678    let advData: bluetoothManager.AdvertiseData = {
2679        serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
2680        manufactureData:[manufactureDataUnit],
2681        serviceData:[serviceDataUnit],
2682    };
2683    let advResponse: bluetoothManager.AdvertiseData = {
2684        serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
2685        manufactureData:[manufactureDataUnit],
2686        serviceData:[serviceDataUnit],
2687    };
2688    gattServer.startAdvertising(setting, advData ,advResponse);
2689} catch (err) {
2690    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2691}
2692```
2693
2694
2695### stopAdvertising<sup>(deprecated)</sup>
2696
2697stopAdvertising(): void
2698
2699停止发送BLE广播。
2700
2701> **说明:**<br/>
2702> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.stopAdvertising](js-apis-bluetooth-ble.md#blestopadvertising)替代。
2703
2704**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2705
2706**系统能力**:SystemCapability.Communication.Bluetooth.Core2707
2708**错误码**:
2709
2710以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2711
2712| 错误码ID | 错误信息 |
2713| -------- | ---------------------------- |
2714|201 | Permission denied.                 |
2715|801 | Capability not supported.          |
2716|2900001 | Service stopped.                         |
2717|2900003 | Bluetooth disabled.                 |
2718|2900099 | Operation failed.                        |
2719
2720**示例:**
2721
2722```js
2723import { BusinessError } from '@ohos.base';
2724let server = bluetoothManager.BLE.createGattServer();
2725try {
2726    server.stopAdvertising();
2727} catch (err) {
2728    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2729}
2730```
2731
2732
2733### addService<sup>(deprecated)</sup>
2734
2735addService(service: GattService): void
2736
2737server端添加服务。
2738
2739> **说明:**<br/>
2740> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#addService](js-apis-bluetooth-ble.md#addservice)替代。
2741
2742**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2743
2744**系统能力**:SystemCapability.Communication.Bluetooth.Core2745
2746**参数:**
2747
2748| 参数名     | 类型                          | 必填   | 说明                       |
2749| ------- | --------------------------- | ---- | ------------------------ |
2750| service | [GattService](#gattservicedeprecated) | 是    | 服务端的service数据。BLE广播的相关参数 |
2751
2752**错误码**:
2753
2754以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2755
2756| 错误码ID | 错误信息 |
2757| -------- | ---------------------------- |
2758|201 | Permission denied.                 |
2759|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2760|801 | Capability not supported.          |
2761|2900001 | Service stopped.                         |
2762|2900003 | Bluetooth disabled.                 |
2763|2900099 | Operation failed.                        |
2764
2765**示例:**
2766
2767```js
2768import { BusinessError } from '@ohos.base';
2769// 创建descriptors
2770let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
2771let arrayBuffer = new ArrayBuffer(8);
2772let descV = new Uint8Array(arrayBuffer);
2773descV[0] = 11;
2774let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2775    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2776    descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
2777descriptors[0] = descriptor;
2778
2779// 创建characteristics
2780let characteristics: Array<bluetoothManager.BLECharacteristic> = [];
2781let arrayBufferC = new ArrayBuffer(8);
2782let cccV = new Uint8Array(arrayBufferC);
2783cccV[0] = 1;
2784let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2785    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
2786let characteristicN: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2787    characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
2788characteristics[0] = characteristic;
2789
2790// 创建gattService
2791let gattService: bluetoothManager.GattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, characteristics:characteristics, includeServices:[]};
2792
2793let gattServer  = bluetoothManager.BLE.createGattServer();
2794try {
2795    gattServer.addService(gattService);
2796} catch (err) {
2797    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2798}
2799```
2800
2801
2802### removeService<sup>(deprecated)</sup>
2803
2804removeService(serviceUuid: string): void
2805
2806删除已添加的服务。
2807
2808> **说明:**<br/>
2809> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#removeService](js-apis-bluetooth-ble.md#removeservice)替代。
2810
2811**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2812
2813**系统能力**:SystemCapability.Communication.Bluetooth.Core2814
2815**参数:**
2816
2817| 参数名         | 类型     | 必填   | 说明                                       |
2818| ----------- | ------ | ---- | ---------------------------------------- |
2819| serviceUuid | string | 是    | service的UUID,例如“00001810-0000-1000-8000-00805F9B34FB”。 |
2820
2821**错误码**:
2822
2823以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2824
2825| 错误码ID | 错误信息 |
2826| -------- | ---------------------------- |
2827|201 | Permission denied.                 |
2828|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2829|801 | Capability not supported.          |
2830|2900001 | Service stopped.                         |
2831|2900003 | Bluetooth disabled.                 |
2832|2900004 | Profile not supported.                |
2833|2900099 | Operation failed.                        |
2834
2835**示例:**
2836
2837```js
2838import { BusinessError } from '@ohos.base';
2839let server = bluetoothManager.BLE.createGattServer();
2840try {
2841    server.removeService('00001810-0000-1000-8000-00805F9B34FB');
2842} catch (err) {
2843    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2844}
2845```
2846
2847
2848### close<sup>(deprecated)</sup>
2849
2850close(): void
2851
2852关闭服务端功能,去注册server在协议栈的注册,调用该接口后[GattServer](#gattserver)实例将不能再使用。
2853
2854> **说明:**<br/>
2855> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#close](js-apis-bluetooth-ble.md#close)替代。
2856
2857**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2858
2859**系统能力**:SystemCapability.Communication.Bluetooth.Core2860
2861**错误码**:
2862
2863以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2864
2865| 错误码ID | 错误信息 |
2866| -------- | ---------------------------- |
2867|201 | Permission denied.                 |
2868|801 | Capability not supported.          |
2869|2900001 | Service stopped.                         |
2870|2900003 | Bluetooth disabled.                 |
2871|2900099 | Operation failed.                        |
2872
2873**示例:**
2874
2875```js
2876import { BusinessError } from '@ohos.base';
2877let server = bluetoothManager.BLE.createGattServer();
2878try {
2879    server.close();
2880} catch (err) {
2881    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2882}
2883```
2884
2885
2886### notifyCharacteristicChanged<sup>(deprecated)</sup>
2887
2888notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): void
2889
2890server端特征值发生变化时,主动通知已连接的client设备。
2891
2892> **说明:**<br/>
2893> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#notifyCharacteristicChanged](js-apis-bluetooth-ble.md#notifycharacteristicchanged)替代。
2894
2895**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2896
2897**系统能力**:SystemCapability.Communication.Bluetooth.Core2898
2899**参数:**
2900
2901| 参数名                  | 类型                                       | 必填   | 说明                                      |
2902| -------------------- | ---------------------------------------- | ---- | --------------------------------------- |
2903| deviceId             | string                                   | 是    | 接收通知的client端设备地址,例如“XX:XX:XX:XX:XX:XX”。 |
2904| notifyCharacteristic | [NotifyCharacteristic](#notifycharacteristicdeprecated) | 是    | 通知的特征值数据。                               |
2905
2906**错误码**:
2907
2908以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2909
2910| 错误码ID | 错误信息 |
2911| -------- | ---------------------------- |
2912|201 | Permission denied.                 |
2913|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2914|801 | Capability not supported.          |
2915|2900001 | Service stopped.                         |
2916|2900003 | Bluetooth disabled.                 |
2917|2900099 | Operation failed.                        |
2918
2919**示例:**
2920
2921```js
2922import { BusinessError } from '@ohos.base';
2923// 创建descriptors
2924let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
2925let arrayBuffer = new ArrayBuffer(8);
2926let descV = new Uint8Array(arrayBuffer);
2927descV[0] = 11;
2928let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2929    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
2930    descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
2931descriptors[0] = descriptor;
2932let arrayBufferC = new ArrayBuffer(8);
2933let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2934  characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
2935let notifyCharacteristic: bluetoothManager.NotifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
2936  characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false};
2937let server = bluetoothManager.BLE.createGattServer();
2938try {
2939    server.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacteristic);
2940} catch (err) {
2941    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2942}
2943```
2944
2945
2946### sendResponse<sup>(deprecated)</sup>
2947
2948sendResponse(serverResponse: ServerResponse): void
2949
2950server端回复client端的读写请求。
2951
2952> **说明:**<br/>
2953> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#sendResponse](js-apis-bluetooth-ble.md#sendresponse)替代。
2954
2955**需要权限**:ohos.permission.ACCESS_BLUETOOTH
2956
2957**系统能力**:SystemCapability.Communication.Bluetooth.Core2958
2959**参数:**
2960
2961| 参数名            | 类型                                | 必填   | 说明              |
2962| -------------- | --------------------------------- | ---- | --------------- |
2963| serverResponse | [ServerResponse](#serverresponsedeprecated) | 是    | server端回复的响应数据。 |
2964
2965**错误码**:
2966
2967以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
2968
2969| 错误码ID | 错误信息 |
2970| -------- | ---------------------------- |
2971|201 | Permission denied.                 |
2972|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
2973|801 | Capability not supported.          |
2974|2900001 | Service stopped.                         |
2975|2900003 | Bluetooth disabled.                 |
2976|2900099 | Operation failed.                        |
2977
2978**示例:**
2979
2980```js
2981import { BusinessError } from '@ohos.base';
2982/* send response */
2983let arrayBufferCCC = new ArrayBuffer(8);
2984let cccValue = new Uint8Array(arrayBufferCCC);
2985cccValue[0] = 1123;
2986let serverResponse: bluetoothManager.ServerResponse = {
2987    deviceId: 'XX:XX:XX:XX:XX:XX',
2988    transId: 0,
2989    status: 0,
2990    offset: 0,
2991    value: arrayBufferCCC,
2992};
2993
2994let gattServer = bluetoothManager.BLE.createGattServer();
2995try {
2996    gattServer.sendResponse(serverResponse);
2997} catch (err) {
2998    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
2999}
3000```
3001
3002
3003### on('characteristicRead')<sup>(deprecated)</sup>
3004
3005on(type: 'characteristicRead', callback: Callback&lt;CharacteristicReadRequest&gt;): void
3006
3007server端订阅特征值读请求事件。
3008
3009> **说明:**<br/>
3010> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#on('characteristicRead')](js-apis-bluetooth-ble.md#oncharacteristicread)替代。
3011
3012**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3013
3014**系统能力**:SystemCapability.Communication.Bluetooth.Core3015
3016**参数:**
3017
3018| 参数名      | 类型                                       | 必填   | 说明                                    |
3019| -------- | ---------------------------------------- | ---- | ------------------------------------- |
3020| type     | string                                   | 是    | 填写"characteristicRead"字符串,表示特征值读请求事件。 |
3021| callback | Callback&lt;[CharacteristicReadRequest](#characteristicreadrequestdeprecated)&gt; | 是    | 表示回调函数的入参,client端发送的读请求数据。            |
3022
3023**错误码**:
3024
3025以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3026
3027| 错误码ID | 错误信息 |
3028| -------- | ---------------------------- |
3029|201 | Permission denied.                 |
3030|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3031|801 | Capability not supported.          |
3032
3033**示例:**
3034
3035```js
3036import { BusinessError } from '@ohos.base';
3037let arrayBufferCCC = new ArrayBuffer(8);
3038let cccValue = new Uint8Array(arrayBufferCCC);
3039cccValue[0] = 1123;
3040function ReadCharacteristicReq(characteristicReadRequest: bluetoothManager.CharacteristicReadRequest) {
3041    let deviceId: string = characteristicReadRequest.deviceId;
3042    let transId: number = characteristicReadRequest.transId;
3043    let offset: number = characteristicReadRequest.offset;
3044    let characteristicUuid: string = characteristicReadRequest.characteristicUuid;
3045
3046    let serverResponse: bluetoothManager.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
3047
3048    try {
3049        gattServer.sendResponse(serverResponse);
3050    } catch (err) {
3051        console.error('errCode: ' + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3052    }
3053}
3054
3055let gattServer = bluetoothManager.BLE.createGattServer();
3056gattServer.on("characteristicRead", ReadCharacteristicReq);
3057```
3058
3059
3060### off('characteristicRead')<sup>(deprecated)</sup>
3061
3062off(type: 'characteristicRead', callback?: Callback&lt;CharacteristicReadRequest&gt;): void
3063
3064server端取消订阅特征值读请求事件。
3065
3066> **说明:**<br/>
3067> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#off('characteristicRead')](js-apis-bluetooth-ble.md#offcharacteristicread)替代。
3068
3069**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3070
3071**系统能力**:SystemCapability.Communication.Bluetooth.Core3072
3073**参数:**
3074
3075| 参数名      | 类型                                       | 必填   | 说明                                       |
3076| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3077| type     | string                                   | 是    | 填写"characteristicRead"字符串,表示特征值读请求事件。    |
3078| callback | Callback&lt;[CharacteristicReadRequest](#characteristicreadrequestdeprecated)&gt; | 否    | 表示取消订阅特征值读请求事件上报。不填该参数则取消订阅该type对应的所有回调。 |
3079
3080**错误码**:
3081
3082以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3083
3084| 错误码ID | 错误信息 |
3085| -------- | ---------------------------- |
3086|201 | Permission denied.                 |
3087|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3088|801 | Capability not supported.          |
3089
3090**示例:**
3091
3092```js
3093import { BusinessError } from '@ohos.base';
3094try {
3095let gattServer = bluetoothManager.BLE.createGattServer();
3096gattServer.off("characteristicRead");
3097} catch (err) {
3098    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3099}
3100```
3101
3102
3103### on('characteristicWrite')<sup>(deprecated)</sup>
3104
3105on(type: 'characteristicWrite', callback: Callback&lt;CharacteristicWriteRequest&gt;): void
3106
3107server端订阅特征值写请求事件。
3108
3109> **说明:**<br/>
3110> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#on('characteristicWrite')](js-apis-bluetooth-ble.md#oncharacteristicwrite)替代。
3111
3112**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3113
3114**系统能力**:SystemCapability.Communication.Bluetooth.Core3115
3116**参数:**
3117
3118| 参数名      | 类型                                       | 必填   | 说明                                     |
3119| -------- | ---------------------------------------- | ---- | -------------------------------------- |
3120| type     | string                                   | 是    | 填写"characteristicWrite"字符串,表示特征值写请求事件。 |
3121| callback | Callback&lt;[CharacteristicWriteRequest](#characteristicwriterequestdeprecated)&gt; | 是    | 表示回调函数的入参,client端发送的写请求数据。             |
3122
3123**错误码**:
3124
3125以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3126
3127| 错误码ID | 错误信息 |
3128| -------- | ---------------------------- |
3129|201 | Permission denied.                 |
3130|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3131|801 | Capability not supported.          |
3132
3133**示例:**
3134
3135```js
3136import { BusinessError } from '@ohos.base';
3137let arrayBufferCCC = new ArrayBuffer(8);
3138let cccValue = new Uint8Array(arrayBufferCCC);
3139function WriteCharacteristicReq(characteristicWriteRequest: bluetoothManager.CharacteristicWriteRequest) {
3140    let deviceId: string = characteristicWriteRequest.deviceId;
3141    let transId: number = characteristicWriteRequest.transId;
3142    let offset: number = characteristicWriteRequest.offset;
3143    let isPrep: boolean = characteristicWriteRequest.isPrep;
3144    let needRsp: boolean = characteristicWriteRequest.needRsp;
3145    let value: Uint8Array =  new Uint8Array(characteristicWriteRequest.value);
3146    let characteristicUuid: string = characteristicWriteRequest.characteristicUuid;
3147
3148    cccValue[0] = value[0];
3149    let serverResponse: bluetoothManager.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
3150
3151    try {
3152        gattServer.sendResponse(serverResponse);
3153    } catch (err) {
3154        console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
3155    }
3156}
3157
3158let gattServer = bluetoothManager.BLE.createGattServer();
3159gattServer.on("characteristicWrite", WriteCharacteristicReq);
3160```
3161
3162
3163### off('characteristicWrite')<sup>(deprecated)</sup>
3164
3165off(type: 'characteristicWrite', callback?: Callback&lt;CharacteristicWriteRequest&gt;): void
3166
3167server端取消订阅特征值写请求事件。
3168
3169> **说明:**<br/>
3170> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#off('characteristicWrite')](js-apis-bluetooth-ble.md#offcharacteristicwrite)替代。
3171
3172**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3173
3174**系统能力**:SystemCapability.Communication.Bluetooth.Core3175
3176**参数:**
3177
3178| 参数名      | 类型                                       | 必填   | 说明                                       |
3179| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3180| type     | string                                   | 是    | 填写"characteristicWrite"字符串,表示特征值写请求事件。   |
3181| callback | Callback&lt;[CharacteristicWriteRequest](#characteristicwriterequestdeprecated)&gt; | 否    | 表示取消订阅特征值写请求事件上报。不填该参数则取消订阅该type对应的所有回调。 |
3182
3183**错误码**:
3184
3185以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3186
3187| 错误码ID | 错误信息 |
3188| -------- | ---------------------------- |
3189|201 | Permission denied.                 |
3190|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3191|801 | Capability not supported.          |
3192
3193**示例:**
3194
3195```js
3196import { BusinessError } from '@ohos.base';
3197try {
3198let gattServer = bluetoothManager.BLE.createGattServer();
3199gattServer.off("characteristicWrite");
3200} catch (err) {
3201    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3202}
3203```
3204
3205
3206### on('descriptorRead')<sup>(deprecated)</sup>
3207
3208on(type: 'descriptorRead', callback: Callback&lt;DescriptorReadRequest&gt;): void
3209
3210server端订阅描述符读请求事件。
3211
3212> **说明:**<br/>
3213> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#on('descriptorRead')](js-apis-bluetooth-ble.md#ondescriptorread)替代。
3214
3215**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3216
3217**系统能力**:SystemCapability.Communication.Bluetooth.Core3218
3219**参数:**
3220
3221| 参数名      | 类型                                       | 必填   | 说明                                |
3222| -------- | ---------------------------------------- | ---- | --------------------------------- |
3223| type     | string                                   | 是    | 填写"descriptorRead"字符串,表示描述符读请求事件。 |
3224| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequestdeprecated)&gt; | 是    | 表示回调函数的入参,client端发送的读请求数据。        |
3225
3226**错误码**:
3227
3228以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3229
3230| 错误码ID | 错误信息 |
3231| -------- | ---------------------------- |
3232|201 | Permission denied.                 |
3233|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3234|801 | Capability not supported.          |
3235
3236**示例:**
3237
3238```js
3239import { BusinessError } from '@ohos.base';
3240let arrayBufferDesc = new ArrayBuffer(8);
3241let descValue = new Uint8Array(arrayBufferDesc);
3242descValue[0] = 1101;
3243function ReadDescriptorReq(descriptorReadRequest: bluetoothManager.DescriptorReadRequest) {
3244    let deviceId: string = descriptorReadRequest.deviceId;
3245    let transId: number = descriptorReadRequest.transId;
3246    let offset: number = descriptorReadRequest.offset;
3247    let descriptorUuid: string = descriptorReadRequest.descriptorUuid;
3248
3249    let serverResponse: bluetoothManager.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
3250
3251    try {
3252        gattServer.sendResponse(serverResponse);
3253    } catch (err) {
3254        console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
3255    }
3256}
3257
3258let gattServer = bluetoothManager.BLE.createGattServer();
3259gattServer.on("descriptorRead", ReadDescriptorReq);
3260```
3261
3262
3263### off('descriptorRead')<sup>(deprecated)</sup>
3264
3265off(type: 'descriptorRead', callback?: Callback&lt;DescriptorReadRequest&gt;): void
3266
3267server端取消订阅描述符读请求事件。
3268
3269> **说明:**<br/>
3270> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#off('descriptorRead')](js-apis-bluetooth-ble.md#offdescriptorread)替代。
3271
3272**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3273
3274**系统能力**:SystemCapability.Communication.Bluetooth.Core3275
3276**参数:**
3277
3278| 参数名      | 类型                                       | 必填   | 说明                                       |
3279| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3280| type     | string                                   | 是    | 填写"descriptorRead"字符串,表示描述符读请求事件。        |
3281| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequestdeprecated)&gt; | 否    | 表示取消订阅描述符读请求事件上报。不填该参数则取消订阅该type对应的所有回调。 |
3282
3283**错误码**:
3284
3285以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3286
3287| 错误码ID | 错误信息 |
3288| -------- | ---------------------------- |
3289|201 | Permission denied.                 |
3290|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3291|801 | Capability not supported.          |
3292
3293**示例:**
3294
3295```js
3296import { BusinessError } from '@ohos.base';
3297try {
3298let gattServer = bluetoothManager.BLE.createGattServer();
3299gattServer.off("descriptorRead");
3300} catch (err) {
3301    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3302}
3303```
3304
3305
3306### on('descriptorWrite')<sup>(deprecated)</sup>
3307
3308on(type: 'descriptorWrite', callback: Callback&lt;DescriptorWriteRequest&gt;): void
3309
3310server端订阅描述符写请求事件。
3311
3312> **说明:**<br/>
3313> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#on('descriptorWrite')](js-apis-bluetooth-ble.md#ondescriptorwrite)替代。
3314
3315**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3316
3317**系统能力**:SystemCapability.Communication.Bluetooth.Core3318
3319**参数:**
3320
3321| 参数名      | 类型                                       | 必填   | 说明                                 |
3322| -------- | ---------------------------------------- | ---- | ---------------------------------- |
3323| type     | string                                   | 是    | 填写"descriptorWrite"字符串,表示描述符写请求事件。 |
3324| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequestdeprecated)&gt; | 是    | 表示回调函数的入参,client端发送的写请求数据。         |
3325
3326**错误码**:
3327
3328以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3329
3330| 错误码ID | 错误信息 |
3331| -------- | ---------------------------- |
3332|201 | Permission denied.                 |
3333|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3334|801 | Capability not supported.          |
3335
3336**示例:**
3337
3338```js
3339import { BusinessError } from '@ohos.base';
3340let arrayBufferDesc = new ArrayBuffer(8);
3341let descValue = new Uint8Array(arrayBufferDesc);
3342function WriteDescriptorReq(descriptorWriteRequest: bluetoothManager.DescriptorWriteRequest) {
3343    let deviceId: string = descriptorWriteRequest.deviceId;
3344    let transId: number = descriptorWriteRequest.transId;
3345    let offset: number = descriptorWriteRequest.offset;
3346    let isPrep: boolean = descriptorWriteRequest.isPrep;
3347    let needRsp: boolean = descriptorWriteRequest.needRsp;
3348    let value: Uint8Array = new Uint8Array(descriptorWriteRequest.value);
3349    let descriptorUuid: string = descriptorWriteRequest.descriptorUuid;
3350
3351    descValue[0] = value[0];
3352    let serverResponse: bluetoothManager.ServerResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
3353
3354    try {
3355        gattServer.sendResponse(serverResponse);
3356    } catch (err) {
3357        console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
3358    }
3359}
3360
3361let gattServer = bluetoothManager.BLE.createGattServer();
3362gattServer.on("descriptorWrite", WriteDescriptorReq);
3363```
3364
3365
3366### off('descriptorWrite')<sup>(deprecated)</sup>
3367
3368off(type: 'descriptorWrite', callback?: Callback&lt;DescriptorWriteRequest&gt;): void
3369
3370server端取消订阅描述符写请求事件。
3371
3372> **说明:**<br/>
3373> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#off('descriptorWrite')](js-apis-bluetooth-ble.md#offdescriptorwrite)替代。
3374
3375**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3376
3377**系统能力**:SystemCapability.Communication.Bluetooth.Core3378
3379**参数:**
3380
3381| 参数名      | 类型                                       | 必填   | 说明                                       |
3382| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3383| type     | string                                   | 是    | 填写"descriptorWrite"字符串,表示描述符写请求事件。       |
3384| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequestdeprecated)&gt; | 否    | 表示取消订阅描述符写请求事件上报。不填该参数则取消订阅该type对应的所有回调。 |
3385
3386**错误码**:
3387
3388以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3389
3390| 错误码ID | 错误信息 |
3391| -------- | ---------------------------- |
3392|201 | Permission denied.                 |
3393|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3394|801 | Capability not supported.          |
3395
3396**示例:**
3397
3398```js
3399import { BusinessError } from '@ohos.base';
3400try {
3401let gattServer = bluetoothManager.BLE.createGattServer();
3402gattServer.off("descriptorWrite");
3403} catch (err) {
3404    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3405}
3406```
3407
3408
3409### on('connectStateChange')<sup>(deprecated)</sup>
3410
3411on(type: 'connectStateChange', callback: Callback&lt;BLEConnectChangedState&gt;): void
3412
3413server端订阅BLE连接状态变化事件。
3414
3415> **说明:**<br/>
3416> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#on('connectionStateChange')](js-apis-bluetooth-ble.md#onconnectionstatechange)替代。
3417
3418**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3419
3420**系统能力**:SystemCapability.Communication.Bluetooth.Core3421
3422**参数:**
3423
3424| 参数名      | 类型                                       | 必填   | 说明                                       |
3425| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3426| type     | string                                   | 是    | 填写"connectStateChange"字符串,表示BLE连接状态变化事件。 |
3427| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstatedeprecated)&gt; | 是    | 表示回调函数的入参,连接状态。                          |
3428
3429**错误码**:
3430
3431以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3432
3433| 错误码ID | 错误信息 |
3434| -------- | ---------------------------- |
3435|201 | Permission denied.                 |
3436|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3437|801 | Capability not supported.          |
3438
3439**示例:**
3440
3441```js
3442import { BusinessError } from '@ohos.base';
3443function Connected(BLEConnectChangedState: bluetoothManager.BLEConnectChangedState) {
3444  let deviceId: string = BLEConnectChangedState.deviceId;
3445  let status: bluetoothManager.ProfileConnectionState  = BLEConnectChangedState.state;
3446}
3447try {
3448let gattServer = bluetoothManager.BLE.createGattServer();
3449gattServer.on("connectStateChange", Connected);
3450} catch (err) {
3451    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3452}
3453```
3454
3455
3456### off('connectStateChange')<sup>(deprecated)</sup>
3457
3458off(type: 'connectStateChange', callback?: Callback&lt;BLEConnectChangedState&gt;): void
3459
3460server端取消订阅BLE连接状态变化事件。
3461
3462> **说明:**<br/>
3463> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattServer#off('connectionStateChange')](js-apis-bluetooth-ble.md#offconnectionstatechange)替代。
3464
3465**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3466
3467**系统能力**:SystemCapability.Communication.Bluetooth.Core3468
3469**参数:**
3470
3471| 参数名      | 类型                                       | 必填   | 说明                                       |
3472| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
3473| type     | string                                   | 是    | 填写"connectStateChange"字符串,表示BLE连接状态变化事件。 |
3474| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstatedeprecated)&gt; | 否    | 表示取消订阅BLE连接状态变化事件。不填该参数则取消订阅该type对应的所有回调。 |
3475
3476**错误码**:
3477
3478以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3479
3480| 错误码ID | 错误信息 |
3481| -------- | ---------------------------- |
3482|201 | Permission denied.                 |
3483|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3484|801 | Capability not supported.          |
3485
3486**示例:**
3487
3488```js
3489import { BusinessError } from '@ohos.base';
3490try {
3491let gattServer = bluetoothManager.BLE.createGattServer();
3492gattServer.off("connectStateChange");
3493} catch (err) {
3494    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3495}
3496```
3497
3498
3499## GattClientDevice
3500
3501client端类,使用client端方法之前需要创建该类的实例进行操作,通过createGattClientDevice(deviceId: string)方法构造此实例。
3502
3503> **说明:**<br/>
3504> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice](js-apis-bluetooth-ble.md#gattclientdevice)替代。
3505
3506
3507### connect<sup>(deprecated)</sup>
3508
3509connect(): void
3510
3511client端发起连接远端蓝牙低功耗设备。
3512
3513> **说明:**<br/>
3514> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#connect](js-apis-bluetooth-ble.md#connect)替代。
3515
3516**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3517
3518**系统能力**:SystemCapability.Communication.Bluetooth.Core3519
3520**错误码**:
3521
3522以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3523
3524| 错误码ID | 错误信息 |
3525| -------- | ---------------------------- |
3526|201 | Permission denied.                 |
3527|801 | Capability not supported.          |
3528|2900001 | Service stopped.                         |
3529|2900003 | Bluetooth disabled.                 |
3530|2900099 | Operation failed.                        |
3531
3532**示例:**
3533
3534```js
3535import { BusinessError } from '@ohos.base';
3536try {
3537    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3538    device.connect();
3539} catch (err) {
3540    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3541}
3542```
3543
3544
3545### disconnect<sup>(deprecated)</sup>
3546
3547disconnect(): void
3548
3549client端断开与远端蓝牙低功耗设备的连接。
3550
3551> **说明:**<br/>
3552> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#disconnect](js-apis-bluetooth-ble.md#disconnect)替代。
3553
3554**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3555
3556**系统能力**:SystemCapability.Communication.Bluetooth.Core3557
3558**错误码**:
3559
3560以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3561
3562| 错误码ID | 错误信息 |
3563| -------- | ---------------------------- |
3564|201 | Permission denied.                 |
3565|801 | Capability not supported.          |
3566|2900001 | Service stopped.                         |
3567|2900003 | Bluetooth disabled.                 |
3568|2900099 | Operation failed.                        |
3569
3570**示例:**
3571
3572```js
3573import { BusinessError } from '@ohos.base';
3574try {
3575    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3576    device.disconnect();
3577} catch (err) {
3578    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3579}
3580```
3581
3582
3583### close<sup>(deprecated)</sup>
3584
3585close(): void
3586
3587关闭客户端功能,注销client在协议栈的注册,调用该接口后[GattClientDevice](#gattclientdevice)实例将不能再使用。
3588
3589> **说明:**<br/>
3590> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#close](js-apis-bluetooth-ble.md#close)替代。
3591
3592**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3593
3594**系统能力**:SystemCapability.Communication.Bluetooth.Core3595
3596**错误码**:
3597
3598以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3599
3600| 错误码ID | 错误信息 |
3601| -------- | ---------------------------- |
3602|201 | Permission denied.                 |
3603|801 | Capability not supported.          |
3604|2900001 | Service stopped.                         |
3605|2900003 | Bluetooth disabled.                 |
3606|2900099 | Operation failed.                        |
3607
3608**示例:**
3609
3610```js
3611import { BusinessError } from '@ohos.base';
3612try {
3613    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3614    device.close();
3615} catch (err) {
3616    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3617}
3618```
3619
3620
3621
3622
3623### getServices<sup>(deprecated)</sup>
3624
3625getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void
3626
3627client端获取蓝牙低功耗设备的所有服务,即服务发现。
3628
3629> **说明:**<br/>
3630> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#getServices](js-apis-bluetooth-ble.md#getservices)替代。
3631
3632**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3633
3634**系统能力**:SystemCapability.Communication.Bluetooth.Core3635
3636**参数:**
3637
3638| 参数名      | 类型                                       | 必填   | 说明                       |
3639| -------- | ---------------------------------------- | ---- | ------------------------ |
3640| callback | AsyncCallback&lt;Array&lt;[GattService](#gattservicedeprecated)&gt;&gt; | 是    | client进行服务发现,通过注册回调函数获取。 |
3641
3642**错误码**:
3643
3644以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3645
3646| 错误码ID | 错误信息 |
3647| -------- | ---------------------------- |
3648|201 | Permission denied.                 |
3649|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.             |
3650|801 | Capability not supported.          |
3651|2900001 | Service stopped.                         |
3652|2900099 | Operation failed.                        |
3653
3654**示例:**
3655
3656```js
3657import { BusinessError } from '@ohos.base';
3658// callback 模式
3659function getServices(code: BusinessError, gattServices: Array<bluetoothManager.GattService>) {
3660  if (code.code == 0) {
3661      let services: Array<bluetoothManager.GattService> = gattServices;
3662      console.log('bluetooth code is ' + code.code);
3663      console.log("bluetooth services size is ", services.length);
3664
3665      for (let i = 0; i < services.length; i++) {
3666        console.log('bluetooth serviceUuid is ' + services[i].serviceUuid);
3667      }
3668  }
3669}
3670
3671try {
3672    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3673    device.connect();
3674    device.getServices(getServices);
3675} catch (err) {
3676    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3677}
3678```
3679
3680
3681### getServices<sup>(deprecated)</sup>
3682
3683getServices(): Promise&lt;Array&lt;GattService&gt;&gt;
3684
3685client端获取蓝牙低功耗设备的所有服务,即服务发现。
3686
3687> **说明:**<br/>
3688> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#getServices](js-apis-bluetooth-ble.md#getservices-1)替代。
3689
3690**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3691
3692**系统能力**:SystemCapability.Communication.Bluetooth.Core3693
3694**返回值:**
3695
3696| 类型                                       | 说明                          |
3697| ---------------------------------------- | --------------------------- |
3698| Promise&lt;Array&lt;[GattService](#gattservicedeprecated)&gt;&gt; | client进行服务发现,通过promise形式获取。 |
3699
3700**错误码**:
3701
3702以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3703
3704| 错误码ID | 错误信息 |
3705| -------- | ---------------------------- |
3706|201 | Permission denied.                 |
3707|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3708|801 | Capability not supported.          |
3709|2900001 | Service stopped.                         |
3710|2900099 | Operation failed.                        |
3711
3712**示例:**
3713
3714```js
3715import { BusinessError } from '@ohos.base';
3716// Promise 模式
3717try {
3718    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3719    device.connect();
3720    device.getServices().then(result => {
3721        console.info("getServices successfully:" + JSON.stringify(result));
3722    });
3723} catch (err) {
3724    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3725}
3726```
3727
3728
3729### readCharacteristicValue<sup>(deprecated)</sup>
3730
3731readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void
3732
3733client端读取蓝牙低功耗设备特定服务的特征值。
3734
3735> **说明:**<br/>
3736> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#readCharacteristicValue](js-apis-bluetooth-ble.md#readcharacteristicvalue)替代。
3737
3738**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3739
3740**系统能力**:SystemCapability.Communication.Bluetooth.Core3741
3742**参数:**
3743
3744| 参数名            | 类型                                       | 必填   | 说明                      |
3745| -------------- | ---------------------------------------- | ---- | ----------------------- |
3746| characteristic | [BLECharacteristic](#blecharacteristicdeprecated)  | 是    | 待读取的特征值。                |
3747| callback       | AsyncCallback&lt;[BLECharacteristic](#blecharacteristicdeprecated)&gt; | 是    | client读取特征值,通过注册回调函数获取。 |
3748
3749**错误码**:
3750
3751以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3752
3753| 错误码ID | 错误信息 |
3754| -------- | ---------------------------- |
3755|201 | Permission denied.                 |
3756|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3757|801 | Capability not supported.          |
3758|2900001 | Service stopped.                         |
3759|2901000 | Read forbidden.                         |
3760|2900099 | Operation failed.                        |
3761
3762**示例:**
3763
3764```js
3765import { BusinessError } from '@ohos.base';
3766function readCcc(code: BusinessError, BLECharacteristic: bluetoothManager.BLECharacteristic) {
3767    if (code.code != 0) {
3768        return;
3769    }
3770    console.log('bluetooth characteristic uuid: ' + BLECharacteristic.characteristicUuid);
3771    let value = new Uint8Array(BLECharacteristic.characteristicValue);
3772    console.log('bluetooth characteristic value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
3773}
3774
3775let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
3776let bufferDesc = new ArrayBuffer(8);
3777let descV = new Uint8Array(bufferDesc);
3778descV[0] = 11;
3779let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3780    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3781    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
3782descriptors[0] = descriptor;
3783
3784let bufferCCC = new ArrayBuffer(8);
3785let cccV = new Uint8Array(bufferCCC);
3786cccV[0] = 1;
3787let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3788    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3789    characteristicValue: bufferCCC, descriptors:descriptors};
3790
3791try {
3792    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3793    device.readCharacteristicValue(characteristic, readCcc);
3794} catch (err) {
3795    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3796}
3797```
3798
3799
3800### readCharacteristicValue<sup>(deprecated)</sup>
3801
3802readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt;
3803
3804client端读取蓝牙低功耗设备特定服务的特征值。
3805
3806> **说明:**<br/>
3807> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#readCharacteristicValue](js-apis-bluetooth-ble.md#readcharacteristicvalue-1)替代。
3808
3809**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3810
3811**系统能力**:SystemCapability.Communication.Bluetooth.Core3812
3813**参数:**
3814
3815| 参数名            | 类型                                      | 必填   | 说明       |
3816| -------------- | --------------------------------------- | ---- | -------- |
3817| characteristic | [BLECharacteristic](#blecharacteristicdeprecated) | 是    | 待读取的特征值。 |
3818
3819**返回值:**
3820
3821| 类型                                       | 说明                         |
3822| ---------------------------------------- | -------------------------- |
3823| Promise&lt;[BLECharacteristic](#blecharacteristicdeprecated)&gt; | client读取特征值,通过promise形式获取。 |
3824
3825**错误码**:
3826
3827以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3828
3829| 错误码ID | 错误信息 |
3830| -------- | ---------------------------- |
3831|201 | Permission denied.                 |
3832|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3833|801 | Capability not supported.          |
3834|2900001 | Service stopped.                         |
3835|2901000 | Read forbidden.                         |
3836|2900099 | Operation failed.                        |
3837
3838**示例:**
3839
3840```js
3841import { BusinessError } from '@ohos.base';
3842let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
3843let bufferDesc = new ArrayBuffer(8);
3844let descV = new Uint8Array(bufferDesc);
3845descV[0] = 11;
3846let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3847    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3848    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
3849descriptors[0] = descriptor;
3850
3851let bufferCCC = new ArrayBuffer(8);
3852let cccV = new Uint8Array(bufferCCC);
3853cccV[0] = 1;
3854let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3855    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3856    characteristicValue: bufferCCC, descriptors:descriptors};
3857
3858try {
3859    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3860    device.readCharacteristicValue(characteristic);
3861} catch (err) {
3862    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3863}
3864```
3865
3866
3867### readDescriptorValue<sup>(deprecated)</sup>
3868
3869readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void
3870
3871client端读取蓝牙低功耗设备特定的特征包含的描述符。
3872
3873> **说明:**<br/>
3874> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#readDescriptorValue](js-apis-bluetooth-ble.md#readdescriptorvalue)替代。
3875
3876**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3877
3878**系统能力**:SystemCapability.Communication.Bluetooth.Core3879
3880**参数:**
3881
3882| 参数名        | 类型                                       | 必填   | 说明                      |
3883| ---------- | ---------------------------------------- | ---- | ----------------------- |
3884| descriptor | [BLEDescriptor](#bledescriptordeprecated)          | 是    | 待读取的描述符。                |
3885| callback   | AsyncCallback&lt;[BLEDescriptor](#bledescriptordeprecated)&gt; | 是    | client读取描述符,通过注册回调函数获取。 |
3886
3887**错误码**:
3888
3889以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3890
3891| 错误码ID | 错误信息 |
3892| -------- | ---------------------------- |
3893|201 | Permission denied.                 |
3894|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3895|801 | Capability not supported.          |
3896|2900001 | Service stopped.                         |
3897|2901000 | Read forbidden.                         |
3898|2900099 | Operation failed.                        |
3899
3900**示例:**
3901
3902```js
3903import { BusinessError } from '@ohos.base';
3904function readDesc(code: BusinessError, BLEDescriptor: bluetoothManager.BLEDescriptor) {
3905    if (code.code != 0) {
3906        return;
3907    }
3908    console.log('bluetooth descriptor uuid: ' + BLEDescriptor.descriptorUuid);
3909    let value = new Uint8Array(BLEDescriptor.descriptorValue);
3910    console.log('bluetooth descriptor value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
3911}
3912
3913let bufferDesc = new ArrayBuffer(8);
3914let descV = new Uint8Array(bufferDesc);
3915descV[0] = 11;
3916let descriptor: bluetoothManager.BLEDescriptor = {
3917    serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3918    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3919    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
3920    descriptorValue: bufferDesc
3921};
3922try {
3923    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3924    device.readDescriptorValue(descriptor, readDesc);
3925} catch (err) {
3926    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3927}
3928```
3929
3930
3931### readDescriptorValue<sup>(deprecated)</sup>
3932
3933readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt;
3934
3935client端读取蓝牙低功耗设备特定的特征包含的描述符。
3936
3937> **说明:**<br/>
3938> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#readDescriptorValue](js-apis-bluetooth-ble.md#readdescriptorvalue-1)替代。
3939
3940**需要权限**:ohos.permission.ACCESS_BLUETOOTH
3941
3942**系统能力**:SystemCapability.Communication.Bluetooth.Core3943
3944**参数:**
3945
3946| 参数名        | 类型                              | 必填   | 说明       |
3947| ---------- | ------------------------------- | ---- | -------- |
3948| descriptor | [BLEDescriptor](#bledescriptordeprecated) | 是    | 待读取的描述符。 |
3949
3950**返回值:**
3951
3952| 类型                                       | 说明                         |
3953| ---------------------------------------- | -------------------------- |
3954| Promise&lt;[BLEDescriptor](#bledescriptordeprecated)&gt; | client读取描述符,通过promise形式获取。 |
3955
3956**错误码**:
3957
3958以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
3959
3960| 错误码ID | 错误信息 |
3961| -------- | ---------------------------- |
3962|201 | Permission denied.                 |
3963|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
3964|801 | Capability not supported.          |
3965|2900001 | Service stopped.                         |
3966|2901000 | Read forbidden.                         |
3967|2900099 | Operation failed.                        |
3968
3969**示例:**
3970
3971```js
3972import { BusinessError } from '@ohos.base';
3973let bufferDesc = new ArrayBuffer(8);
3974let descV = new Uint8Array(bufferDesc);
3975descV[0] = 11;
3976let descriptor: bluetoothManager.BLEDescriptor = {
3977    serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
3978    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
3979    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
3980    descriptorValue: bufferDesc
3981};
3982try {
3983    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
3984    device.readDescriptorValue(descriptor);
3985} catch (err) {
3986    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
3987}
3988```
3989
3990
3991### writeCharacteristicValue<sup>(deprecated)</sup>
3992
3993writeCharacteristicValue(characteristic: BLECharacteristic): void
3994
3995client端向低功耗蓝牙设备写入特定的特征值。
3996
3997> **说明:**<br/>
3998> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#writeCharacteristicValue](js-apis-bluetooth-ble.md#writecharacteristicvalue)替代。
3999
4000**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4001
4002**系统能力**:SystemCapability.Communication.Bluetooth.Core4003
4004**参数:**
4005
4006| 参数名            | 类型                                      | 必填   | 说明                  |
4007| -------------- | --------------------------------------- | ---- | ------------------- |
4008| characteristic | [BLECharacteristic](#blecharacteristicdeprecated) | 是    | 蓝牙设备特征对应的二进制值及其它参数。 |
4009
4010**错误码**:
4011
4012以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4013
4014| 错误码ID | 错误信息 |
4015| -------- | ---------------------------- |
4016|201 | Permission denied.                 |
4017|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
4018|801 | Capability not supported.          |
4019|2900001 | Service stopped.                         |
4020|2901001 | Write forbidden.                        |
4021|2900099 | Operation failed.                        |
4022
4023**示例:**
4024
4025```js
4026import { BusinessError } from '@ohos.base';
4027let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
4028let bufferDesc = new ArrayBuffer(8);
4029let descV = new Uint8Array(bufferDesc);
4030descV[0] = 11;
4031let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
4032    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
4033    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
4034descriptors[0] = descriptor;
4035
4036let bufferCCC = new ArrayBuffer(8);
4037let cccV = new Uint8Array(bufferCCC);
4038cccV[0] = 1;
4039let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
4040    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
4041    characteristicValue: bufferCCC, descriptors:descriptors};
4042try {
4043    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4044    device.writeCharacteristicValue(characteristic);
4045} catch (err) {
4046    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4047}
4048```
4049
4050
4051### writeDescriptorValue<sup>(deprecated)</sup>
4052
4053writeDescriptorValue(descriptor: BLEDescriptor): void
4054
4055client端向低功耗蓝牙设备特定的描述符写入二进制数据。
4056
4057> **说明:**<br/>
4058> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#writeCharacteristicValue](js-apis-bluetooth-ble.md#writecharacteristicvalue-1)替代。
4059
4060**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4061
4062**系统能力**:SystemCapability.Communication.Bluetooth.Core4063
4064**参数:**
4065
4066| 参数名        | 类型                              | 必填   | 说明                 |
4067| ---------- | ------------------------------- | ---- | ------------------ |
4068| descriptor | [BLEDescriptor](#bledescriptordeprecated) | 是    | 蓝牙设备描述符的二进制值及其它参数。 |
4069
4070**错误码**:
4071
4072以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4073
4074| 错误码ID | 错误信息 |
4075| -------- | ---------------------------- |
4076|201 | Permission denied.                 |
4077|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
4078|801 | Capability not supported.          |
4079|2900001 | Service stopped.                         |
4080|2901001 | Write forbidden.                        |
4081|2900099 | Operation failed.                        |
4082
4083**示例:**
4084
4085```js
4086import { BusinessError } from '@ohos.base';
4087let bufferDesc = new ArrayBuffer(8);
4088let descV = new Uint8Array(bufferDesc);
4089descV[0] = 22;
4090let descriptor: bluetoothManager.BLEDescriptor = {
4091    serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
4092    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
4093    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
4094    descriptorValue: bufferDesc
4095};
4096try {
4097    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4098    device.writeDescriptorValue(descriptor);
4099} catch (err) {
4100    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4101}
4102```
4103
4104
4105### setBLEMtuSize<sup>(deprecated)</sup>
4106
4107setBLEMtuSize(mtu: number): void
4108
4109client协商远端蓝牙低功耗设备的最大传输单元(Maximum Transmission Unit, MTU),调用[connect](#connect)接口连接成功后才能使用。
4110
4111> **说明:**<br/>
4112> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#setBLEMtuSize](js-apis-bluetooth-ble.md#setBLEMtuSize)替代。
4113
4114**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4115
4116**系统能力**:SystemCapability.Communication.Bluetooth.Core4117
4118**参数:**
4119
4120| 参数名  | 类型     | 必填   | 说明             |
4121| ---- | ------ | ---- | -------------- |
4122| mtu  | number | 是    | 设置范围为22~512字节。 |
4123
4124**错误码**:
4125
4126以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4127
4128| 错误码ID | 错误信息 |
4129| -------- | ---------------------------- |
4130|201 | Permission denied.                 |
4131|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                |
4132|801 | Capability not supported.          |
4133|2900001 | Service stopped.                         |
4134|2900099 | Operation failed.                        |
4135
4136**示例:**
4137
4138```js
4139import { BusinessError } from '@ohos.base';
4140try {
4141    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4142    device.setBLEMtuSize(128);
4143} catch (err) {
4144    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4145}
4146```
4147
4148
4149### setNotifyCharacteristicChanged<sup>(deprecated)</sup>
4150
4151setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): void
4152
4153向服务端发送设置通知此特征值请求。
4154
4155> **说明:**<br/>
4156> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#setCharacteristicChangeNotification](js-apis-bluetooth-ble.md#setcharacteristicchangenotification)替代。
4157
4158**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4159
4160**系统能力**:SystemCapability.Communication.Bluetooth.Core4161
4162**参数:**
4163
4164| 参数名            | 类型                                      | 必填   | 说明                            |
4165| -------------- | --------------------------------------- | ---- | ----------------------------- |
4166| characteristic | [BLECharacteristic](#blecharacteristicdeprecated) | 是    | 蓝牙低功耗特征。                      |
4167| enable         | boolean                                 | 是    | 启用接收notify设置为true,否则设置为false。 |
4168
4169**错误码**:
4170
4171以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4172
4173| 错误码ID | 错误信息 |
4174| -------- | ---------------------------- |
4175|201 | Permission denied.                 |
4176|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
4177|801 | Capability not supported.          |
4178|2900001 | Service stopped.                         |
4179|2900099 | Operation failed.                        |
4180
4181**示例:**
4182
4183```js
4184import { BusinessError } from '@ohos.base';
4185// 创建descriptors
4186let descriptors: Array<bluetoothManager.BLEDescriptor> = [];
4187let bufferDesc = new ArrayBuffer(8);
4188let descV = new Uint8Array(bufferDesc);
4189descV[0] = 11;
4190let descriptor: bluetoothManager.BLEDescriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
4191    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
4192    descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
4193descriptors[0] = descriptor;
4194
4195let bufferCCC = new ArrayBuffer(8);
4196let cccV = new Uint8Array(bufferCCC);
4197cccV[0] = 1;
4198let characteristic: bluetoothManager.BLECharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
4199    characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
4200    characteristicValue: bufferCCC, descriptors:descriptors};
4201try {
4202    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4203    device.setNotifyCharacteristicChanged(characteristic, false);
4204} catch (err) {
4205    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4206}
4207
4208```
4209
4210
4211### on('BLECharacteristicChange')<sup>(deprecated)</sup>
4212
4213on(type: 'BLECharacteristicChange', callback: Callback&lt;BLECharacteristic&gt;): void
4214
4215订阅蓝牙低功耗设备的特征值变化事件。需要先调用setNotifyCharacteristicChanged接口才能接收server端的通知。
4216
4217> **说明:**<br/>
4218> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#on('BLECharacteristicChange')](js-apis-bluetooth-ble.md#onblecharacteristicchange)替代。
4219
4220**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4221
4222**系统能力**:SystemCapability.Communication.Bluetooth.Core4223
4224**参数:**
4225
4226| 参数名      | 类型                                       | 必填   | 说明                                       |
4227| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
4228| type     | string                                   | 是    | 填写"BLECharacteristicChange"字符串,表示特征值变化事件。 |
4229| callback | Callback&lt;[BLECharacteristic](#blecharacteristicdeprecated)&gt; | 是    | 表示蓝牙低功耗设备的特征值变化事件的回调函数。                  |
4230
4231**错误码**:
4232
4233以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4234
4235| 错误码ID | 错误信息 |
4236| -------- | ---------------------------- |
4237|201 | Permission denied.                 |
4238|801 | Capability not supported.          |
4239
4240**示例:**
4241
4242```js
4243import { BusinessError } from '@ohos.base';
4244function CharacteristicChange(characteristicChangeReq: ble.BLECharacteristic) {
4245    let serviceUuid: string = characteristicChangeReq.serviceUuid;
4246    let characteristicUuid: string = characteristicChangeReq.characteristicUuid;
4247    let value: Uint8Array = new Uint8Array(characteristicChangeReq.characteristicValue);
4248}
4249try {
4250    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4251    device.on('BLECharacteristicChange', CharacteristicChange);
4252} catch (err) {
4253    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4254}
4255```
4256
4257
4258### off('BLECharacteristicChange')<sup>(deprecated)</sup>
4259
4260off(type: 'BLECharacteristicChange', callback?: Callback&lt;BLECharacteristic&gt;): void
4261
4262取消订阅蓝牙低功耗设备的特征值变化事件。
4263
4264> **说明:**<br/>
4265> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#off('BLECharacteristicChange')](js-apis-bluetooth-ble.md#offblecharacteristicchange)替代。
4266
4267**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4268
4269**系统能力**:SystemCapability.Communication.Bluetooth.Core4270
4271**参数:**
4272
4273| 参数名      | 类型                                       | 必填   | 说明                                       |
4274| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
4275| type     | string                                   | 是    | 填写"BLECharacteristicChange"字符串,表示特征值变化事件。 |
4276| callback | Callback&lt;[BLECharacteristic](#blecharacteristicdeprecated)&gt; | 否    | 表示取消订阅蓝牙低功耗设备的特征值变化事件。不填该参数则取消订阅该type对应的所有回调。 |
4277
4278**错误码**:
4279
4280以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4281
4282| 错误码ID | 错误信息 |
4283| -------- | ---------------------------- |
4284|201 | Permission denied.                 |
4285|801 | Capability not supported.          |
4286
4287**示例:**
4288
4289```js
4290import { BusinessError } from '@ohos.base';
4291try {
4292    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4293    device.off('BLECharacteristicChange');
4294} catch (err) {
4295    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4296}
4297```
4298
4299
4300### on('BLEConnectionStateChange')<sup>(deprecated)</sup>
4301
4302on(type: 'BLEConnectionStateChange', callback: Callback&lt;BLEConnectChangedState&gt;): void
4303
4304client端订阅蓝牙低功耗设备的连接状态变化事件。
4305
4306> **说明:**<br/>
4307> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#on('BLEConnectionStateChange')](js-apis-bluetooth-ble.md#onbleconnectionstatechange)替代。
4308
4309**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4310
4311**系统能力**:SystemCapability.Communication.Bluetooth.Core4312
4313**参数:**
4314
4315| 参数名      | 类型                                       | 必填   | 说明                                       |
4316| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
4317| type     | string                                   | 是    | 填写"BLEConnectionStateChange"字符串,表示连接状态变化事件。 |
4318| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstatedeprecated)&gt; | 是    | 表示连接状态,已连接或断开。                           |
4319
4320**错误码**:
4321
4322以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4323
4324| 错误码ID | 错误信息 |
4325| -------- | ---------------------------- |
4326|201 | Permission denied.                 |
4327|801 | Capability not supported.          |
4328
4329**示例:**
4330
4331```js
4332import { BusinessError } from '@ohos.base';
4333function ConnectStateChanged(state: bluetoothManager.BLEConnectChangedState) {
4334    console.log('bluetooth connect state changed');
4335    let connectState: bluetoothManager.ProfileConnectionState = state.state;
4336}
4337try {
4338    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4339    device.on('BLEConnectionStateChange', ConnectStateChanged);
4340} catch (err) {
4341    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4342}
4343```
4344
4345
4346### off('BLEConnectionStateChange')<sup>(deprecated)</sup>
4347
4348off(type: 'BLEConnectionStateChange', callback?: Callback&lt;BLEConnectChangedState&gt;): void
4349
4350取消订阅蓝牙低功耗设备的连接状态变化事件。
4351
4352> **说明:**<br/>
4353> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#off('BLEConnectionStateChange')](js-apis-bluetooth-ble.md#offbleconnectionstatechange)替代。
4354
4355**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4356
4357**系统能力**:SystemCapability.Communication.Bluetooth.Core4358
4359**参数:**
4360
4361| 参数名      | 类型                                       | 必填   | 说明                                       |
4362| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
4363| type     | string                                   | 是    | 填写"BLEConnectionStateChange"字符串,表示连接状态变化事件。 |
4364| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstatedeprecated)&gt; | 否    | 表示取消订阅蓝牙低功耗设备的连接状态变化事件。不填该参数则取消订阅该type对应的所有回调。 |
4365
4366**错误码**:
4367
4368以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4369
4370| 错误码ID | 错误信息 |
4371| -------- | ---------------------------- |
4372|201 | Permission denied.                 |
4373|801 | Capability not supported.          |
4374
4375**示例:**
4376
4377```js
4378import { BusinessError } from '@ohos.base';
4379try {
4380    let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
4381    device.off('BLEConnectionStateChange');
4382} catch (err) {
4383    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4384}
4385```
4386
4387
4388### getDeviceName<sup>(deprecated)</sup>
4389
4390getDeviceName(callback: AsyncCallback&lt;string&gt;): void
4391
4392client获取远端蓝牙低功耗设备名。
4393
4394> **说明:**<br/>
4395> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#getDeviceName](js-apis-bluetooth-ble.md#getdevicename)替代。
4396
4397**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4398
4399**系统能力**:SystemCapability.Communication.Bluetooth.Core4400
4401**参数:**
4402
4403| 参数名      | 类型                          | 必填   | 说明                              |
4404| -------- | --------------------------- | ---- | ------------------------------- |
4405| callback | AsyncCallback&lt;string&gt; | 是    | client获取对端server设备名,通过注册回调函数获取。 |
4406
4407**错误码**:
4408
4409以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4410
4411| 错误码ID | 错误信息 |
4412| -------- | ---------------------------- |
4413|201 | Permission denied.                 |
4414|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.              |
4415|801 | Capability not supported.          |
4416|2900001 | Service stopped.                         |
4417|2900099 | Operation failed.                        |
4418
4419**示例:**
4420
4421```js
4422import { BusinessError } from '@ohos.base';
4423// callback
4424try {
4425    let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
4426    gattClient.connect();
4427    let deviceName = gattClient.getDeviceName((err, data)=> {
4428        console.info('device name err ' + JSON.stringify(err));
4429        console.info('device name' + JSON.stringify(data));
4430    })
4431} catch (err) {
4432    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4433}
4434```
4435
4436
4437### getDeviceName<sup>(deprecated)</sup>
4438
4439getDeviceName(): Promise&lt;string&gt;
4440
4441client获取远端蓝牙低功耗设备名。
4442
4443> **说明:**<br/>
4444> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#getDeviceName](js-apis-bluetooth-ble.md#getdevicename-1)替代。
4445
4446**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4447
4448**系统能力**:SystemCapability.Communication.Bluetooth.Core4449
4450**返回值:**
4451
4452| 类型                    | 说明                                 |
4453| --------------------- | ---------------------------------- |
4454| Promise&lt;string&gt; | client获取对端server设备名,通过promise形式获取。 |
4455
4456**错误码**:
4457
4458以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4459
4460| 错误码ID | 错误信息 |
4461| -------- | ---------------------------- |
4462|201 | Permission denied.                 |
4463|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.              |
4464|801 | Capability not supported.          |
4465|2900001 | Service stopped.                         |
4466|2900099 | Operation failed.                        |
4467
4468**示例:**
4469
4470```js
4471import { BusinessError } from '@ohos.base';
4472// promise
4473try {
4474    let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
4475    gattClient.connect();
4476    let deviceName = gattClient.getDeviceName().then((data) => {
4477        console.info('device name' + JSON.stringify(data));
4478    })
4479} catch (err) {
4480    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4481}
4482```
4483
4484
4485### getRssiValue<sup>(deprecated)</sup>
4486
4487getRssiValue(callback: AsyncCallback&lt;number&gt;): void
4488
4489client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI),调用[connect](#connect)接口连接成功后才能使用。
4490
4491> **说明:**<br/>
4492> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#getRssiValue](js-apis-bluetooth-ble.md#getrssivalue)替代。
4493
4494**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4495
4496**系统能力**:SystemCapability.Communication.Bluetooth.Core4497
4498**参数:**
4499
4500| 参数名      | 类型                          | 必填   | 说明                             |
4501| -------- | --------------------------- | ---- | ------------------------------ |
4502| callback | AsyncCallback&lt;number&gt; | 是    | 返回信号强度,单位&nbsp;dBm,通过注册回调函数获取。 |
4503
4504**错误码**:
4505
4506以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4507
4508| 错误码ID | 错误信息 |
4509| -------- | ---------------------------- |
4510|201 | Permission denied.                 |
4511|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.              |
4512|801 | Capability not supported.          |
4513|2900099 | Operation failed.                        |
4514
4515**示例:**
4516
4517```js
4518import { BusinessError } from '@ohos.base';
4519// callback
4520try {
4521    let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
4522    gattClient.connect();
4523    let rssi = gattClient.getRssiValue((err: BusinessError, data: number)=> {
4524        console.info('rssi err ' + JSON.stringify(err));
4525        console.info('rssi value' + JSON.stringify(data));
4526    })
4527} catch (err) {
4528    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4529}
4530```
4531
4532
4533### getRssiValue<sup>(deprecated)</sup>
4534
4535getRssiValue(): Promise&lt;number&gt;
4536
4537client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI),调用[connect](#connect)接口连接成功后才能使用。
4538
4539> **说明:**<br/>
4540> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattClientDevice#getRssiValue](js-apis-bluetooth-ble.md#getrssivalue-1)替代。
4541
4542**需要权限**:ohos.permission.ACCESS_BLUETOOTH
4543
4544**系统能力**:SystemCapability.Communication.Bluetooth.Core4545
4546**返回值:**
4547
4548| 类型                    | 说明                                |
4549| --------------------- | --------------------------------- |
4550| Promise&lt;number&gt; | 返回信号强度,单位&nbsp;dBm,通过promise形式获取。 |
4551
4552**错误码**:
4553
4554以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
4555
4556| 错误码ID | 错误信息 |
4557| -------- | ---------------------------- |
4558|201 | Permission denied.                 |
4559|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.               |
4560|801 | Capability not supported.          |
4561|2900099 | Operation failed.                        |
4562
4563**示例:**
4564
4565```js
4566import { BusinessError } from '@ohos.base';
4567// promise
4568try {
4569    let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
4570    let rssi = gattClient.getRssiValue().then((data: number) => {
4571        console.info('rssi' + JSON.stringify(data));
4572    })
4573} catch (err) {
4574    console.error("errCode:" + (err as BusinessError).code + ",errMessage:" + (err as BusinessError).message);
4575}
4576```
4577
4578## ScanMode<sup>(deprecated)</sup>
4579
4580枚举,扫描模式。
4581
4582> **说明:**<br/>
4583> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.ScanMode](js-apis-bluetooth-connection.md#scanmode)替代。
4584
4585**系统能力**:SystemCapability.Communication.Bluetooth.Core4586
4587| 名称                                       | 值  | 说明              |
4588| ---------------------------------------- | ---- | --------------- |
4589| SCAN_MODE_NONE                           | 0    | 没有扫描模式。         |
4590| SCAN_MODE_CONNECTABLE                    | 1    | 可连接扫描模式。        |
4591| SCAN_MODE_GENERAL_DISCOVERABLE           | 2    | general发现模式。    |
4592| SCAN_MODE_LIMITED_DISCOVERABLE           | 3    | limited发现模式。    |
4593| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4    | 可连接general发现模式。 |
4594| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5    | 可连接limited发现模式。 |
4595
4596## BondState<sup>(deprecated)</sup>
4597
4598枚举,配对状态。
4599
4600> **说明:**<br/>
4601> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.BondState](js-apis-bluetooth-connection.md#bondstate)替代。
4602
4603**系统能力**:SystemCapability.Communication.Bluetooth.Core4604
4605| 名称                 | 值  | 说明     |
4606| ------------------ | ---- | ------ |
4607| BOND_STATE_INVALID | 0    | 无效的配对。 |
4608| BOND_STATE_BONDING | 1    | 正在配对。  |
4609| BOND_STATE_BONDED  | 2    | 已配对。   |
4610
4611
4612## SppOption<sup>(deprecated)</sup>
4613
4614描述spp的配置参数。
4615
4616> **说明:**<br/>
4617> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.SppOption](js-apis-bluetooth-socket.md#sppoptions)替代。
4618
4619**系统能力**:SystemCapability.Communication.Bluetooth.Core4620
4621| 名称     | 类型                | 可读   | 可写   | 说明          |
4622| ------ | ------------------- | ---- | ---- | ----------- |
4623| uuid   | string              | 是    | 是    | spp单据的uuid。 |
4624| secure | boolean             | 是    | 是    | 是否是安全通道。    |
4625| type   | [SppType](#spptypedeprecated) | 是    | 是    | Spp链路类型。    |
4626
4627
4628## SppType<sup>(deprecated)</sup>
4629
4630枚举,Spp链路类型。
4631
4632> **说明:**<br/>
4633> 从API version 9开始支持,从API version 10开始废弃。建议使用[socket.SppType](js-apis-bluetooth-socket.md#spptype)替代。
4634
4635**系统能力**:SystemCapability.Communication.Bluetooth.Core4636
4637| 名称         | 值  | 说明            |
4638| ---------- | ---- | ------------- |
4639| SPP_RFCOMM | 0    | 表示rfcomm链路类型。 |
4640
4641
4642## GattService<sup>(deprecated)</sup>
4643
4644描述service的接口参数定义。
4645
4646> **说明:**<br/>
4647> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.GattService](js-apis-bluetooth-ble.md#gattservice)替代。
4648
4649**系统能力**:SystemCapability.Communication.Bluetooth.Core4650
4651| 名称              | 类型                                     | 可读   | 可写   | 说明                                       |
4652| --------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
4653| serviceUuid     | string                                   | 是    | 是    | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4654| isPrimary       | boolean                                  | 是    | 是    | 如果是主服务设置为true,否则设置为false。                |
4655| characteristics | Array&lt;[BLECharacteristic](#blecharacteristicdeprecated)&gt; | 是    | 是    | 当前服务包含的特征列表。                             |
4656| includeServices | Array&lt;[GattService](#gattservicedeprecated)&gt; | 是    | 是    | 当前服务依赖的其它服务。                             |
4657
4658
4659## BLECharacteristic<sup>(deprecated)</sup>
4660
4661描述characteristic的接口参数定义。
4662
4663> **说明:**<br/>
4664> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.BLECharacteristic](js-apis-bluetooth-ble.md#blecharacteristic)替代。
4665
4666**系统能力**:SystemCapability.Communication.Bluetooth.Core4667
4668| 名称                  | 类型                                     | 可读   | 可写   | 说明                                 |
4669| ------------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
4670| serviceUuid         | string                                   | 是    | 是    | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4671| characteristicUuid  | string                                   | 是    | 是    | 特定特征(characteristic)的UUID,例如:00002a11-0000-1000-8000-00805f9b34fb。 |
4672| characteristicValue | ArrayBuffer                              | 是    | 是    | 特征对应的二进制值。                      |
4673| descriptors         | Array&lt;[BLEDescriptor](#bledescriptordeprecated)&gt; | 是    | 是    | 特定特征的描述符列表。                |
4674
4675
4676## BLEDescriptor<sup>(deprecated)</sup>
4677
4678描述descriptor的接口参数定义。
4679
4680> **说明:**<br/>
4681> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.BLEDescriptor](js-apis-bluetooth-ble.md#bledescriptor)替代。
4682
4683**系统能力**:SystemCapability.Communication.Bluetooth.Core4684
4685| 名称                 | 类型        | 可读   | 可写   | 说明                                       |
4686| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
4687| serviceUuid        | string      | 是    | 是    | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4688| characteristicUuid | string      | 是    | 是    | 特定特征(characteristic)的UUID,例如:00002a11-0000-1000-8000-00805f9b34fb。 |
4689| descriptorUuid     | string      | 是    | 是    | 描述符(descriptor)的UUID,例如:00002902-0000-1000-8000-00805f9b34fb。 |
4690| descriptorValue    | ArrayBuffer | 是    | 是    | 描述符对应的二进制值。                              |
4691
4692
4693## NotifyCharacteristic<sup>(deprecated)</sup>
4694
4695描述server端特征值变化时发送的特征通知参数定义。
4696
4697> **说明:**<br/>
4698> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.NotifyCharacteristic](js-apis-bluetooth-ble.md#notifycharacteristic)替代。
4699
4700**系统能力**:SystemCapability.Communication.Bluetooth.Core4701
4702| 名称                  | 类型        | 可读   | 可写   | 说明                                       |
4703| ------------------- | ----------- | ---- | ---- | ---------------------------------------- |
4704| serviceUuid         | string      | 是    | 是    | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4705| characteristicUuid  | string      | 是    | 是    | 特定特征(characteristic)的UUID,例如:00002a11-0000-1000-8000-00805f9b34fb。 |
4706| characteristicValue | ArrayBuffer | 是    | 是    | 特征对应的二进制值。                               |
4707| confirm             | boolean     | 是    | 是    | 如果是notification则对端回复确认设置为true,如果是indication则对端不需要回复确认设置为false。 |
4708
4709
4710## CharacteristicReadRequest<sup>(deprecated)</sup>
4711
4712描述server端订阅后收到的特征值读请求事件参数结构。
4713
4714> **说明:**<br/>
4715> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.CharacteristicReadRequest](js-apis-bluetooth-ble.md#characteristicreadrequest)替代。
4716
4717**系统能力**:SystemCapability.Communication.Bluetooth.Core4718
4719| 名称                 | 类型   | 可读   | 可写   | 说明                                       |
4720| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
4721| deviceId           | string | 是    | 否    | 表示发送特征值读请求的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
4722| transId            | number | 是    | 否    | 表示读请求的传输ID,server端回复响应时需填写相同的传输ID。       |
4723| offset             | number | 是    | 否    | 表示读特征值数据的起始位置。例如:k表示从第k个字节开始读,server端回复响应时需填写相同的offset。 |
4724| characteristicUuid | string | 是    | 否    | 特定特征(characteristic)的UUID,例如:00002a11-0000-1000-8000-00805f9b34fb。 |
4725| serviceUuid        | string | 是    | 否    | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4726
4727
4728## CharacteristicWriteRequest<sup>(deprecated)</sup>
4729
4730描述server端订阅后收到的特征值写请求事件参数结构。
4731
4732> **说明:**<br/>
4733> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.CharacteristicWriteRequest](js-apis-bluetooth-ble.md#characteristicwriterequest)替代。
4734
4735**系统能力**:SystemCapability.Communication.Bluetooth.Core4736
4737| 名称                 | 类型   | 可读   | 可写   | 说明                                       |
4738| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
4739| deviceId           | string | 是    | 否    | 表示发送特征值写请求的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
4740| transId            | number | 是    | 否    | 表示写请求的传输ID,server端回复响应时需填写相同的传输ID。       |
4741| offset             | number | 是    | 否    | 表示写特征值数据的起始位置。例如:k表示从第k个字节开始写,server端回复响应时需填写相同的offset。 |
4742| isPrep             | boolean | 是    | 否    | 表示写请求是否立即执行。true表示立即执行。 |
4743| needRsp            | boolean | 是    | 否    | 表示是否要给client端回复响应。true表示需要回复。 |
4744| value              | ArrayBuffer | 是    | 否    | 表示写入的描述符二进制数据。 |
4745| characteristicUuid | string | 是    | 否    | 特定特征(characteristic)的UUID,例如:00002a11-0000-1000-8000-00805f9b34fb。 |
4746| serviceUuid        | string | 是    | 否    | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4747
4748
4749## DescriptorReadRequest<sup>(deprecated)</sup>
4750
4751描述server端订阅后收到的描述符读请求事件参数结构。
4752
4753> **说明:**<br/>
4754> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.DescriptorReadRequest](js-apis-bluetooth-ble.md#descriptorreadrequest)替代。
4755
4756**系统能力**:SystemCapability.Communication.Bluetooth.Core4757
4758| 名称                 | 类型   | 可读   | 可写   | 说明                                       |
4759| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
4760| deviceId           | string | 是    | 否    | 表示发送描述符读请求的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
4761| transId            | number | 是    | 否    | 表示读请求的传输ID,server端回复响应时需填写相同的传输ID。       |
4762| offset             | number | 是    | 否    | 表示读描述符数据的起始位置。例如:k表示从第k个字节开始读,server端回复响应时需填写相同的offset。 |
4763| descriptorUuid     | string | 是    | 否    | 表示描述符(descriptor)的UUID,例如:00002902-0000-1000-8000-00805f9b34fb。 |
4764| characteristicUuid | string | 是    | 否    | 特定特征(characteristic)的UUID,例如:00002a11-0000-1000-8000-00805f9b34fb。 |
4765| serviceUuid        | string | 是    | 否    | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4766
4767
4768## DescriptorWriteRequest<sup>(deprecated)</sup>
4769
4770描述server端订阅后收到的描述符写请求事件参数结构。
4771
4772> **说明:**<br/>
4773> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.DescriptorWriteRequest](js-apis-bluetooth-ble.md#descriptorwriterequest)替代。
4774
4775**系统能力**:SystemCapability.Communication.Bluetooth.Core4776
4777| 名称                 | 类型        | 可读   | 可写   | 说明                                       |
4778| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
4779| deviceId           | string      | 是    | 否    | 表示发送描述符写请求的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
4780| transId            | number      | 是    | 否    | 表示写请求的传输ID,server端回复响应时需填写相同的传输ID。       |
4781| offset             | number      | 是    | 否    | 表示写描述符数据的起始位置。例如:k表示从第k个字节开始写,server端回复响应时需填写相同的offset。 |
4782| isPrep             | boolean     | 是    | 否    | 表示写请求是否立即执行。                             |
4783| needRsp            | boolean     | 是    | 否    | 表示是否要给client端回复响应。                       |
4784| value              | ArrayBuffer | 是    | 否    | 表示写入的描述符二进制数据。                           |
4785| descriptorUuid     | string      | 是    | 否    | 表示描述符(descriptor)的UUID,例如:00002902-0000-1000-8000-00805f9b34fb。 |
4786| characteristicUuid | string      | 是    | 否    | 特定特征(characteristic)的UUID,例如:00002a11-0000-1000-8000-00805f9b34fb。 |
4787| serviceUuid        | string      | 是    | 否    | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4788
4789
4790## ServerResponse<sup>(deprecated)</sup>
4791
4792描述server端回复client端读/写请求的响应参数结构。
4793
4794> **说明:**<br/>
4795> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.ServerResponse](js-apis-bluetooth-ble.md#serverresponse)替代。
4796
4797**系统能力**:SystemCapability.Communication.Bluetooth.Core4798
4799| 名称       | 类型        | 可读   | 可写   | 说明                                     |
4800| -------- | ----------- | ---- | ---- | -------------------------------------- |
4801| deviceId | string      | 是    | 否    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。       |
4802| transId  | number      | 是    | 否    | 表示请求的传输ID,与订阅的读/写请求事件携带的ID保持一致。        |
4803| status   | number      | 是    | 否    | 表示响应的状态,设置为0即可,表示正常。                   |
4804| offset   | number      | 是    | 否    | 表示请求的读/写起始位置,与订阅的读/写请求事件携带的offset保持一致。 |
4805| value    | ArrayBuffer | 是    | 否    | 表示回复响应的二进制数据。                          |
4806
4807
4808## BLEConnectChangedState<sup>(deprecated)</sup>
4809
4810描述Gatt profile连接状态。
4811
4812> **说明:**<br/>
4813> 从API version 9开始支持,从API version 10开始废弃。建议使用[BLEConnectionChangeState](js-apis-bluetooth-ble.md#bleconnectionchangestate)替代。
4814
4815**系统能力**:SystemCapability.Communication.Bluetooth.Core4816
4817| 名称     | 类型                                          | 可读 | 可写 | 说明                                          |
4818| -------- | ------------------------------------------------- | ---- | ---- | --------------------------------------------- |
4819| deviceId | string                                            | 是   | 否   | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
4820| state    | [ProfileConnectionState](#profileconnectionstatedeprecated) | 是   | 是   | 表示BLE连接状态的枚举。                       |
4821
4822
4823## ProfileConnectionState<sup>(deprecated)</sup>
4824
4825枚举,蓝牙设备的profile连接状态。
4826
4827> **说明:**<br/>
4828> 从API version 9开始支持,从API version 10开始废弃。建议使用[constant.ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate)替代。
4829
4830**系统能力**:SystemCapability.Communication.Bluetooth.Core4831
4832| 名称                  | 值  | 说明             |
4833| ------------------- | ---- | -------------- |
4834| STATE_DISCONNECTED  | 0    | 表示profile已断连。  |
4835| STATE_CONNECTING    | 1    | 表示profile正在连接。 |
4836| STATE_CONNECTED     | 2    | 表示profile已连接。  |
4837| STATE_DISCONNECTING | 3    | 表示profile正在断连。 |
4838
4839
4840## ScanFilter<sup>(deprecated)</sup>
4841
4842扫描过滤参数。
4843
4844> **说明:**<br/>
4845> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.ScanFilter](js-apis-bluetooth-ble.md#scanfilter)替代。
4846
4847**系统能力**:SystemCapability.Communication.Bluetooth.Core4848
4849| 名称                                     | 类型    | 可读 | 可写 | 说明                                                         |
4850| ---------------------------------------- | ----------- | ---- | ---- | ------------------------------------------------------------ |
4851| deviceId                                 | string      | 是   | 是   | 表示过滤的BLE设备地址,例如:"XX:XX:XX:XX:XX:XX"。           |
4852| name                                     | string      | 是   | 是   | 表示过滤的BLE设备名。                                        |
4853| serviceUuid                              | string      | 是   | 是   | 表示过滤包含该UUID服务的设备,例如:00001888-0000-1000-8000-00805f9b34fb。 |
4854| serviceUuidMask             | string      | 是   | 是   | 表示过滤包含该UUID服务掩码的设备,例如:FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF。 |
4855| serviceSolicitationUuid     | string      | 是   | 是   | 表示过滤包含该UUID服务请求的设备,例如:00001888-0000-1000-8000-00805F9B34FB。 |
4856| serviceSolicitationUuidMask | string      | 是   | 是   | 表示过滤包含该UUID服务请求掩码的设备,例如:FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF。 |
4857| serviceData                 | ArrayBuffer | 是   | 是   | 表示过滤包含该服务相关数据的设备,例如:[0x90,0x00,0xF1,0xF2]。 |
4858| serviceDataMask             | ArrayBuffer | 是   | 是   | 表示过滤包含该服务相关数据掩码的设备,例如:[0xFF,0xFF,0xFF,0xFF]。 |
4859| manufactureId               | number      | 是   | 是   | 表示过滤包含该制造商ID的设备,例如:0x0006。                 |
4860| manufactureData             | ArrayBuffer | 是   | 是   | 表示过滤包含该制造商相关数据的设备,例如:[0x1F,0x2F,0x3F]。 |
4861| manufactureDataMask         | ArrayBuffer | 是   | 是   | 表示过滤包含该制造商相关数据掩码的设备,例如:[0xFF,0xFF,0xFF]。 |
4862
4863
4864## ScanOptions<sup>(deprecated)</sup>
4865
4866扫描的配置参数。
4867
4868> **说明:**<br/>
4869> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.ScanOptions](js-apis-bluetooth-ble.md#scanoptions)替代。
4870
4871**系统能力**:SystemCapability.Communication.Bluetooth.Core4872
4873| 名称        | 类型                    | 可读   | 可写   | 说明                                     |
4874| --------- | ----------------------- | ---- | ---- | -------------------------------------- |
4875| interval  | number                  | 是    | 是    | 表示扫描结果上报延迟时间,默认值为0。                    |
4876| dutyMode  | [ScanDuty](#scandutydeprecated)   | 是    | 是    | 表示扫描模式,默认值为SCAN_MODE_LOW_POWER。        |
4877| matchMode | [MatchMode](#matchmodedeprecated) | 是    | 是    | 表示硬件的过滤匹配模式,默认值为MATCH_MODE_AGGRESSIVE。 |
4878
4879
4880## ScanDuty<sup>(deprecated)</sup>
4881
4882枚举,扫描模式。
4883
4884> **说明:**<br/>
4885> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.ScanDuty](js-apis-bluetooth-ble.md#scanduty)替代。
4886
4887**系统能力**:SystemCapability.Communication.Bluetooth.Core4888
4889| 名称                    | 值  | 说明           |
4890| --------------------- | ---- | ------------ |
4891| SCAN_MODE_LOW_POWER   | 0    | 表示低功耗模式,默认值。 |
4892| SCAN_MODE_BALANCED    | 1    | 表示均衡模式。      |
4893| SCAN_MODE_LOW_LATENCY | 2    | 表示低延迟模式。     |
4894
4895
4896## MatchMode<sup>(deprecated)</sup>
4897
4898枚举,硬件过滤匹配模式。
4899
4900> **说明:**<br/>
4901> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.MatchMode](js-apis-bluetooth-ble.md#matchmode)替代。
4902
4903**系统能力**:SystemCapability.Communication.Bluetooth.Core4904
4905| 名称                    | 值  | 说明                                       |
4906| --------------------- | ---- | ---------------------------------------- |
4907| MATCH_MODE_AGGRESSIVE | 1    | 表示硬件上报扫描结果门限较低,比如扫描到的功率较低或者一段时间扫描到的次数较少也触发上报,默认值。 |
4908| MATCH_MODE_STICKY     | 2    | 表示硬件上报扫描结果门限较高,更高的功率门限以及扫描到多次才会上报。       |
4909
4910
4911## ScanResult<sup>(deprecated)</sup>
4912
4913扫描结果上报数据。
4914
4915> **说明:**<br/>
4916> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.ScanResult](js-apis-bluetooth-ble.md#scanresult)替代。
4917
4918**系统能力**:SystemCapability.Communication.Bluetooth.Core4919
4920| 名称       | 类型        | 可读   | 可写   | 说明                                 |
4921| -------- | ----------- | ---- | ---- | ---------------------------------- |
4922| deviceId | string      | 是    | 否    | 表示扫描到的设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
4923| rssi     | number      | 是    | 否    | 表示扫描到的设备的rssi值。                    |
4924| data     | ArrayBuffer | 是    | 否    | 表示扫描到的设备发送的广播包。                    |
4925
4926
4927## BluetoothState<sup>(deprecated)</sup>
4928
4929枚举,蓝牙开关状态。
4930
4931> **说明:**<br/>
4932> 从API version 9开始支持,从API version 10开始废弃。建议使用[access.BluetoothState](js-apis-bluetooth-access.md#bluetoothstate)替代。
4933
4934**系统能力**:SystemCapability.Communication.Bluetooth.Core4935
4936| 名称                    | 值  | 说明                 |
4937| --------------------- | ---- | ------------------ |
4938| STATE_OFF             | 0    | 表示蓝牙已关闭。           |
4939| STATE_TURNING_ON      | 1    | 表示蓝牙正在打开。          |
4940| STATE_ON              | 2    | 表示蓝牙已打开。           |
4941| STATE_TURNING_OFF     | 3    | 表示蓝牙正在关闭。          |
4942| STATE_BLE_TURNING_ON  | 4    | 表示蓝牙正在打开LE-only模式。 |
4943| STATE_BLE_ON          | 5    | 表示蓝牙正处于LE-only模式。  |
4944| STATE_BLE_TURNING_OFF | 6    | 表示蓝牙正在关闭LE-only模式。 |
4945
4946
4947## AdvertiseSetting<sup>(deprecated)</sup>
4948
4949描述蓝牙低功耗设备发送广播的参数。
4950
4951> **说明:**<br/>
4952> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.AdvertiseSetting](js-apis-bluetooth-ble.md#advertisesetting)替代。
4953
4954**系统能力**:SystemCapability.Communication.Bluetooth.Core4955
4956| 名称          | 类型    | 可读   | 可写   | 说明                                       |
4957| ----------- | ------- | ---- | ---- | ---------------------------------------- |
4958| interval    | number  | 是    | 是    | 表示广播间隔,最小值设置32个slot表示20ms,最大值设置16384个slot,默认值设置为1600个slot表示1s。 |
4959| txPower     | number  | 是    | 是    | 表示发送功率,最小值设置-127,最大值设置1,默认值设置-7,单位dbm。   |
4960| connectable | boolean | 是    | 是    | 表示是否是可连接广播,默认值设置为true。                   |
4961
4962
4963## AdvertiseData<sup>(deprecated)</sup>
4964
4965描述BLE广播数据包的内容。
4966
4967> **说明:**<br/>
4968> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.AdvertiseData](js-apis-bluetooth-ble.md#advertisedata)替代。
4969
4970**系统能力**:SystemCapability.Communication.Bluetooth.Core4971
4972| 名称              | 类型                                     | 可读   | 可写   | 说明                          |
4973| --------------- | ---------------------------------------- | ---- | ---- | --------------------------- |
4974| serviceUuids    | Array&lt;string&gt;                      | 是    | 是    | 表示要广播的服务&nbsp;UUID&nbsp;列表。 |
4975| manufactureData | Array&lt;[ManufactureData](#manufacturedatadeprecated)&gt; | 是    | 是    | 表示要广播的广播的制造商信息列表。           |
4976| serviceData     | Array&lt;[ServiceData](#servicedatadeprecated)&gt; | 是    | 是    | 表示要广播的服务数据列表。               |
4977
4978
4979## ManufactureData<sup>(deprecated)</sup>
4980
4981描述BLE广播数据包的内容。
4982
4983> **说明:**<br/>
4984> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.ManufactureData](js-apis-bluetooth-ble.md#manufacturedata)替代。
4985
4986**系统能力**:SystemCapability.Communication.Bluetooth.Core4987
4988| 名称               | 类型                | 可读   | 可写   | 说明                 |
4989| ---------------- | ------------------- | ---- | ---- | ------------------ |
4990| manufactureId    | number  | 是    | 是    | 表示制造商的ID,由蓝牙SIG分配。 |
4991| manufactureValue | ArrayBuffer         | 是    | 是    | 表示制造商发送的制造商数据。     |
4992
4993
4994## ServiceData<sup>(deprecated)</sup>
4995
4996描述广播包中服务数据内容。
4997
4998> **说明:**<br/>
4999> 从API version 9开始支持,从API version 10开始废弃。建议使用[ble.ServiceData](js-apis-bluetooth-ble.md#servicedata)替代。
5000
5001**系统能力**:SystemCapability.Communication.Bluetooth.Core5002
5003| 名称           | 类型        | 可读   | 可写   | 说明         |
5004| ------------ | ----------- | ---- | ---- | ---------- |
5005| serviceUuid  | string      | 是    | 是    | 表示服务的UUID。 |
5006| serviceValue | ArrayBuffer | 是    | 是    | 表示服务数据。    |
5007
5008
5009## PinRequiredParam<sup>(deprecated)</sup>
5010
5011描述配对请求参数。
5012
5013> **说明:**<br/>
5014> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.PinRequiredParam](js-apis-bluetooth-connection.md#pinrequiredparam)替代。
5015
5016**系统能力**:SystemCapability.Communication.Bluetooth.Core5017
5018| 名称       | 类型   | 可读   | 可写   | 说明          |
5019| -------- | ------ | ---- | ---- | ----------- |
5020| deviceId | string | 是    | 否    | 表示要配对的设备ID。 |
5021| pinCode  | string | 是    | 否    | 表示要配对的密钥。   |
5022
5023
5024## BondStateParam<sup>(deprecated)</sup>
5025
5026描述配对状态参数。
5027
5028> **说明:**<br/>
5029> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.BondStateParam](js-apis-bluetooth-connection.md#bondstateparam)替代。
5030
5031**系统能力**:SystemCapability.Communication.Bluetooth.Core5032
5033| 名称       | 类型   | 可读   | 可写   | 说明          |
5034| -------- | ------ | ---- | ---- | ----------- |
5035| deviceId | string      | 是    | 否    | 表示要配对的设备ID。 |
5036| state    | BondState   | 是    | 否    | 表示配对设备的状态。 |
5037
5038
5039## StateChangeParam<sup>(deprecated)</sup>
5040
5041描述profile状态改变参数。
5042
5043> **说明:**<br/>
5044> 从API version 9开始支持,从API version 10开始废弃。建议使用[baseProfile.StateChangeParam](js-apis-bluetooth-baseProfile.md#statechangeparam)替代。
5045
5046**系统能力**:SystemCapability.Communication.Bluetooth.Core5047
5048| 名称     | 类型                                          | 可读 | 可写 | 说明                            |
5049| -------- | ------------------------------------------------- | ---- | ---- | ------------------------------- |
5050| deviceId | string                                            | 是   | 否   | 表示蓝牙设备地址。              |
5051| state    | [ProfileConnectionState](#profileconnectionstatedeprecated) | 是   | 否   | 表示蓝牙设备的profile连接状态。 |
5052
5053
5054## DeviceClass<sup>(deprecated)</sup>
5055
5056描述蓝牙设备的类别。
5057
5058> **说明:**<br/>
5059> 从API version 9开始支持,从API version 10开始废弃。建议使用[connection.DeviceClass](js-apis-bluetooth-connection.md#deviceclass)替代。
5060
5061**系统能力**:SystemCapability.Communication.Bluetooth.Core5062
5063| 名称              | 类型                                | 可读   | 可写   | 说明               |
5064| --------------- | ----------------------------------- | ---- | ---- | ---------------- |
5065| majorClass      | [MajorClass](#majorclassdeprecated)           | 是    | 否    | 表示蓝牙设备主要类别的枚举。   |
5066| majorMinorClass | [MajorMinorClass](#majorminorclassdeprecated) | 是    | 否    | 表示主要次要蓝牙设备类别的枚举。 |
5067| classOfDevice   | number                              | 是    | 否    | 表示设备类别。          |
5068
5069
5070## MajorClass<sup>(deprecated)</sup>
5071
5072枚举,蓝牙设备主要类别。
5073
5074> **说明:**<br/>
5075> 从API version 9开始支持,从API version 10开始废弃。建议使用[constant.MajorClass](js-apis-bluetooth-constant.md#majorclass)替代。
5076
5077**系统能力**:SystemCapability.Communication.Bluetooth.Core5078
5079| 名称                  | 值    | 说明         |
5080| ------------------- | ------ | ---------- |
5081| MAJOR_MISC          | 0x0000 | 表示杂项设备。    |
5082| MAJOR_COMPUTER      | 0x0100 | 表示计算机设备。   |
5083| MAJOR_PHONE         | 0x0200 | 表示手机设备。    |
5084| MAJOR_NETWORKING    | 0x0300 | 表示网络设备。    |
5085| MAJOR_AUDIO_VIDEO   | 0x0400 | 表示音频和视频设备。 |
5086| MAJOR_PERIPHERAL    | 0x0500 | 表示外围设备。    |
5087| MAJOR_IMAGING       | 0x0600 | 表示成像设备。    |
5088| MAJOR_WEARABLE      | 0x0700 | 表示可穿戴设备。   |
5089| MAJOR_TOY           | 0x0800 | 表示玩具设备。    |
5090| MAJOR_HEALTH        | 0x0900 | 表示健康设备。    |
5091| MAJOR_UNCATEGORIZED | 0x1F00 | 表示未分类设备。   |
5092
5093
5094## MajorMinorClass<sup>(deprecated)</sup>
5095
5096枚举,主要次要蓝牙设备类别。
5097
5098> **说明:**<br/>
5099> 从API version 9开始支持,从API version 10开始废弃。建议使用[constant.MajorMinorClass](js-apis-bluetooth-constant.md#majorminorclass)替代。
5100
5101**系统能力**:SystemCapability.Communication.Bluetooth.Core5102
5103| 名称                                       | 值    | 说明              |
5104| ---------------------------------------- | ------ | --------------- |
5105| COMPUTER_UNCATEGORIZED                   | 0x0100 | 表示未分类计算机设备。     |
5106| COMPUTER_DESKTOP                         | 0x0104 | 表示台式计算机设备。      |
5107| COMPUTER_SERVER                          | 0x0108 | 表示服务器设备。        |
5108| COMPUTER_LAPTOP                          | 0x010C | 表示便携式计算机设备。     |
5109| COMPUTER_HANDHELD_PC_PDA                 | 0x0110 | 表示手持式计算机设备。     |
5110| COMPUTER_PALM_SIZE_PC_PDA                | 0x0114 | 表示掌上电脑设备。       |
5111| COMPUTER_WEARABLE                        | 0x0118 | 表示可穿戴计算机设备。     |
5112| COMPUTER_TABLET                          | 0x011C | 表示平板电脑设备。       |
5113| PHONE_UNCATEGORIZED                      | 0x0200 | 表示未分类手机设备。      |
5114| PHONE_CELLULAR                           | 0x0204 | 表示便携式手机设备。      |
5115| PHONE_CORDLESS                           | 0x0208 | 表示无线电话设备。       |
5116| PHONE_SMART                              | 0x020C | 表示智能手机设备。       |
5117| PHONE_MODEM_OR_GATEWAY                   | 0x0210 | 表示调制解调器或网关手机设备。 |
5118| PHONE_ISDN                               | 0x0214 | 表示ISDN手机设备。     |
5119| NETWORK_FULLY_AVAILABLE                  | 0x0300 | 表示网络完全可用设备。     |
5120| NETWORK_1_TO_17_UTILIZED                 | 0x0320 | 表示使用网络1到17设备。   |
5121| NETWORK_17_TO_33_UTILIZED                | 0x0340 | 表示使用网络17到33设备。  |
5122| NETWORK_33_TO_50_UTILIZED                | 0x0360 | 表示使用网络33到50设备。  |
5123| NETWORK_60_TO_67_UTILIZED                | 0x0380 | 表示使用网络60到67设备。  |
5124| NETWORK_67_TO_83_UTILIZED                | 0x03A0 | 表示使用网络67到83设备。  |
5125| NETWORK_83_TO_99_UTILIZED                | 0x03C0 | 表示使用网络83到99设备。  |
5126| NETWORK_NO_SERVICE                       | 0x03E0 | 表示网络无服务设备。      |
5127| AUDIO_VIDEO_UNCATEGORIZED                | 0x0400 | 表示未分类音频视频设备。    |
5128| AUDIO_VIDEO_WEARABLE_HEADSET             | 0x0404 | 表示可穿戴式音频视频设备。   |
5129| AUDIO_VIDEO_HANDSFREE                    | 0x0408 | 表示免提音频视频设备。     |
5130| AUDIO_VIDEO_MICROPHONE                   | 0x0410 | 表示麦克风音频视频设备。    |
5131| AUDIO_VIDEO_LOUDSPEAKER                  | 0x0414 | 表示扬声器音频视频设备。    |
5132| AUDIO_VIDEO_HEADPHONES                   | 0x0418 | 表示头戴式音频视频设备。    |
5133| AUDIO_VIDEO_PORTABLE_AUDIO               | 0x041C | 表示便携式音频视频设备。    |
5134| AUDIO_VIDEO_CAR_AUDIO                    | 0x0420 | 表示汽车音频视频设备。     |
5135| AUDIO_VIDEO_SET_TOP_BOX                  | 0x0424 | 表示机顶盒音频视频设备。    |
5136| AUDIO_VIDEO_HIFI_AUDIO                   | 0x0428 | 表示高保真音响设备。      |
5137| AUDIO_VIDEO_VCR                          | 0x042C | 表示录像机音频视频设备。    |
5138| AUDIO_VIDEO_VIDEO_CAMERA                 | 0x0430 | 表示照相机音频视频设备。    |
5139| AUDIO_VIDEO_CAMCORDER                    | 0x0434 | 表示摄像机音频视频设备。    |
5140| AUDIO_VIDEO_VIDEO_MONITOR                | 0x0438 | 表示监视器音频视频设备。    |
5141| AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER | 0x043C | 表示视频显示器和扬声器设备。  |
5142| AUDIO_VIDEO_VIDEO_CONFERENCING           | 0x0440 | 表示音频视频会议设备。     |
5143| AUDIO_VIDEO_VIDEO_GAMING_TOY             | 0x0448 | 表示游戏玩具音频视频设备。   |
5144| PERIPHERAL_NON_KEYBOARD_NON_POINTING     | 0x0500 | 表示非键盘非指向外围设备。   |
5145| PERIPHERAL_KEYBOARD                      | 0x0540 | 表示外设键盘设备。       |
5146| PERIPHERAL_POINTING_DEVICE               | 0x0580 | 表示定点装置外围设备。     |
5147| PERIPHERAL_KEYBOARD_POINTING             | 0x05C0 | 表示键盘指向外围设备。     |
5148| PERIPHERAL_UNCATEGORIZED                 | 0x0500 | 表示未分类外围设备。      |
5149| PERIPHERAL_JOYSTICK                      | 0x0504 | 表示周边操纵杆设备。      |
5150| PERIPHERAL_GAMEPAD                       | 0x0508 | 表示周边游戏板设备。      |
5151| PERIPHERAL_REMOTE_CONTROL                | 0x05C0 | 表示远程控制外围设备。     |
5152| PERIPHERAL_SENSING_DEVICE                | 0x0510 | 表示外围传感设备设备。     |
5153| PERIPHERAL_DIGITIZER_TABLET              | 0x0514 | 表示外围数字化仪平板电脑设备。 |
5154| PERIPHERAL_CARD_READER                   | 0x0518 | 表示外围读卡器设备。      |
5155| PERIPHERAL_DIGITAL_PEN                   | 0x051C | 表示外设数码笔设备。      |
5156| PERIPHERAL_SCANNER_RFID                  | 0x0520 | 表示射频识别扫描仪外围设备。  |
5157| PERIPHERAL_GESTURAL_INPUT                | 0x0522 | 表示手势输入外围设备。     |
5158| IMAGING_UNCATEGORIZED                    | 0x0600 | 表示未分类的图像设备。     |
5159| IMAGING_DISPLAY                          | 0x0610 | 表示图像显示设备。       |
5160| IMAGING_CAMERA                           | 0x0620 | 表示成像照相机设备。      |
5161| IMAGING_SCANNER                          | 0x0640 | 表示成像扫描仪设备。      |
5162| IMAGING_PRINTER                          | 0x0680 | 表示成像打印机设备。      |
5163| WEARABLE_UNCATEGORIZED                   | 0x0700 | 表示未分类的可穿戴设备。    |
5164| WEARABLE_WRIST_WATCH                     | 0x0704 | 表示可穿戴腕表设备。      |
5165| WEARABLE_PAGER                           | 0x0708 | 表示可穿戴寻呼机设备。     |
5166| WEARABLE_JACKET                          | 0x070C | 表示夹克可穿戴设备。      |
5167| WEARABLE_HELMET                          | 0x0710 | 表示可穿戴头盔设备。      |
5168| WEARABLE_GLASSES                         | 0x0714 | 表示可穿戴眼镜设备。      |
5169| TOY_UNCATEGORIZED                        | 0x0800 | 表示未分类的玩具设备。     |
5170| TOY_ROBOT                                | 0x0804 | 表示玩具机器人设备。      |
5171| TOY_VEHICLE                              | 0x0808 | 表示玩具车设备。        |
5172| TOY_DOLL_ACTION_FIGURE                   | 0x080C | 表示人形娃娃玩具设备。     |
5173| TOY_CONTROLLER                           | 0x0810 | 表示玩具控制器设备。      |
5174| TOY_GAME                                 | 0x0814 | 表示玩具游戏设备。       |
5175| HEALTH_UNCATEGORIZED                     | 0x0900 | 表示未分类健康设备。      |
5176| HEALTH_BLOOD_PRESSURE                    | 0x0904 | 表示血压健康设备。       |
5177| HEALTH_THERMOMETER                       | 0x0908 | 表示温度计健康设备。      |
5178| HEALTH_WEIGHING                          | 0x090C | 表示体重健康设备。       |
5179| HEALTH_GLUCOSE                           | 0x0910 | 表示葡萄糖健康设备。      |
5180| HEALTH_PULSE_OXIMETER                    | 0x0914 | 表示脉搏血氧仪健康设备。    |
5181| HEALTH_PULSE_RATE                        | 0x0918 | 表示脉搏率健康设备。      |
5182| HEALTH_DATA_DISPLAY                      | 0x091C | 表示数据显示健康设备。     |
5183| HEALTH_STEP_COUNTER                      | 0x0920 | 表示阶梯计数器健康设备。    |
5184| HEALTH_BODY_COMPOSITION_ANALYZER         | 0x0924 | 表示身体成分分析仪健康设备。  |
5185| HEALTH_PEAK_FLOW_MONITOR                  | 0x0928 | 表示湿度计健康设备。      |
5186| HEALTH_MEDICATION_MONITOR                | 0x092C | 表示药物监视仪健康设备。    |
5187| HEALTH_KNEE_PROSTHESIS                   | 0x0930 | 表示膝盖假肢健康设备。     |
5188| HEALTH_ANKLE_PROSTHESIS                  | 0x0934 | 表示脚踝假肢健康设备。     |
5189| HEALTH_GENERIC_HEALTH_MANAGER            | 0x0938 | 表示通用健康管理设备。     |
5190| HEALTH_PERSONAL_MOBILITY_DEVICE          | 0x093C | 表示个人移动健康设备。     |
5191
5192
5193## PlayingState<sup>(deprecated)</sup>
5194
5195枚举,蓝牙A2DP 播放状态。
5196
5197> **说明:**<br/>
5198> 从API version 9开始支持,从API version 10开始废弃。建议使用[a2dp.PlayingState](js-apis-bluetooth-a2dp.md#playingstate)替代。
5199
5200**系统能力**:SystemCapability.Communication.Bluetooth.Core5201
5202| 名称                | 值    | 说明      |
5203| ----------------- | ------ | ------- |
5204| STATE_NOT_PLAYING | 0x0000 | 表示未播放。  |
5205| STATE_PLAYING     | 0x0001 | 表示正在播放。 |
5206
5207
5208## ProfileId<sup>(deprecated)</sup>
5209
5210蓝牙profile枚举,API9新增PROFILE_HID_HOST,PROFILE_PAN_NETWORK。
5211
5212> **说明:**<br/>
5213> 从API version 9开始支持,从API version 10开始废弃。建议使用[constant.ProfileId](js-apis-bluetooth-constant.md#profileid)替代。
5214
5215**系统能力**:SystemCapability.Communication.Bluetooth.Core5216
5217| 名称                               | 值    | 说明              |
5218| -------------------------------- | ------ | --------------- |
5219| PROFILE_A2DP_SOURCE              | 1 | 表示A2DP profile。 |
5220| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | 表示HFP profile。  |
5221| PROFILE_HID_HOST | 6 | 表示HID profile。  |
5222| PROFILE_PAN_NETWORK | 7 | 表示PAN profile。  |
5223