• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bluetooth.connection (蓝牙connection模块)(系统接口)
2
3connection模块提供了对蓝牙操作和管理的方法。
4
5> **说明:**
6>
7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.connection (蓝牙connection模块)](js-apis-bluetooth-connection.md)
9
10
11## 导入模块
12
13```js
14import connection from '@ohos.bluetooth.connection';
15```
16
17
18## connection.pairCredibleDevice
19
20pairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback<void>): void
21
22向可信的远端设备发起蓝牙配对。通过非蓝牙扫描的方式(例如NFC等)获取到外设的地址,可以通过该接口发起配对。
23
24**系统接口**:此接口为系统接口。
25
26**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
27
28**系统能力**:SystemCapability.Communication.Bluetooth.Core29
30**参数:**
31
32| 参数名      | 类型     | 必填   | 说明                                  |
33| -------- | ------ | ---- | ----------------------------------- |
34| deviceId | string | 是    | 表示配对的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
35| transport | [BluetoothTransport](js-apis-bluetooth-connection.md#bluetoothtransport) | 是    | 表示设备类型,例如传统蓝牙设备或低功耗蓝牙设备。 |
36| callback | AsyncCallback<void> | 是    | 回调函数。当发起配对成功,err为undefined,否则为错误对象。   |
37
38**错误码**:
39
40以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
41
42| 错误码ID | 错误信息 |
43| -------- | ---------------------------- |
44|2900001 | Service stopped.                         |
45|2900003 | Bluetooth switch is off.                 |
46|2900099 | Operation failed.                        |
47
48**示例:**
49
50```js
51import { BusinessError } from '@ohos.base';
52try {
53    connection.pairCredibleDevice('68:13:24:79:4C:8C', connection.BluetoothTransport
54        .TRANSPORT_BR_EDR, (err: BusinessError) => {
55        if (err) {
56            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
57            return;
58        }
59        console.info('pairCredibleDevice, err: ' + JSON.stringify(err));
60    });
61} catch (err) {
62    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
63}
64```
65
66
67## connection.pairCredibleDevice
68
69pairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise<void>
70
71向可信的远端设备发起蓝牙配对。通过非蓝牙扫描的方式(例如NFC等)获取到外设的地址,可以通过该接口发起配对。
72
73**系统接口**:此接口为系统接口。
74
75**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
76
77**系统能力**:SystemCapability.Communication.Bluetooth.Core78
79**参数:**
80
81| 参数名      | 类型     | 必填   | 说明                                  |
82| -------- | ------ | ---- | ----------------------------------- |
83| deviceId | string | 是    | 表示配对的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
84| transport | [BluetoothTransport](js-apis-bluetooth-connection.md#bluetoothtransport) | 是    | 表示设备类型,例如传统蓝牙设备或低功耗蓝牙设备。 |
85
86**返回值:**
87
88| 类型                                              | 说明                |
89| ------------------------------------------------- | ------------------- |
90| Promise<void> | 返回promise对象。 |
91
92**错误码**:
93
94以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
95
96| 错误码ID | 错误信息 |
97| -------- | ---------------------------- |
98|2900001 | Service stopped.                         |
99|2900003 | Bluetooth switch is off.                 |
100|2900099 | Operation failed.                        |
101
102**示例:**
103
104```js
105import { BusinessError } from '@ohos.base';
106try {
107    connection.pairCredibleDevice('68:13:24:79:4C:8C', 0).then(() => {
108        console.info('PairCredibleDevice');
109    }, (err: BusinessError) => {
110        console.error('PairCredibleDevice:errCode' + err.code + ', errMessage: ' + err.message);
111    });
112} catch (err) {
113    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
114}
115```
116
117
118## connection.cancelPairedDevice
119
120cancelPairedDevice(deviceId: string, callback: AsyncCallback<void>): void
121
122删除配对的远程设备。
123
124**系统接口**:此接口为系统接口。
125
126**需要权限**:ohos.permission.ACCESS_BLUETOOTH
127
128**系统能力**:SystemCapability.Communication.Bluetooth.Core129
130**参数:**
131
132| 参数名      | 类型     | 必填   | 说明                                    |
133| -------- | ------ | ---- | ------------------------------------- |
134| deviceId | string | 是    | 表示要删除的远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
135| callback | AsyncCallback<void> | 是    | 回调函数。当删除远程配对设备成功,err为undefined,否则为错误对象。   |
136
137**错误码**:
138
139以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
140
141| 错误码ID | 错误信息 |
142| -------- | ---------------------------- |
143|2900001 | Service stopped.                         |
144|2900003 | Bluetooth switch is off.                 |
145|2900099 | Operation failed.                        |
146
147**示例:**
148
149```js
150import { BusinessError } from '@ohos.base';
151try {
152    connection.cancelPairedDevice('XX:XX:XX:XX:XX:XX');
153} catch (err) {
154    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
155}
156```
157
158
159## connection.cancelPairedDevice
160
161cancelPairedDevice(deviceId: string): Promise<void>
162
163删除配对的远程设备。
164
165**系统接口**:此接口为系统接口。
166
167**需要权限**:ohos.permission.ACCESS_BLUETOOTH
168
169**系统能力**:SystemCapability.Communication.Bluetooth.Core170
171**参数:**
172
173| 参数名      | 类型     | 必填   | 说明                                    |
174| -------- | ------ | ---- | ------------------------------------- |
175| deviceId | string | 是    | 表示要删除的远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
176
177**返回值:**
178
179| 类型                  | 说明            |
180| ------------------- | ------------- |
181| Promise<void> | 返回promise对象。 |
182
183**错误码**:
184
185以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
186
187| 错误码ID | 错误信息 |
188| -------- | ---------------------------- |
189|2900001 | Service stopped.                         |
190|2900003 | Bluetooth switch is off.                 |
191|2900099 | Operation failed.                        |
192
193**示例:**
194
195```js
196import { BusinessError } from '@ohos.base';
197try {
198    connection.cancelPairedDevice('XX:XX:XX:XX:XX:XX');
199} catch (err) {
200    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
201}
202```
203
204
205## connection.cancelPairingDevice
206
207cancelPairingDevice(deviceId: string, callback: AsyncCallback<void>): void
208
209删除正在配对中的远程设备。
210
211**系统接口**:此接口为系统接口。
212
213**需要权限**:ohos.permission.ACCESS_BLUETOOTH
214
215**系统能力**:SystemCapability.Communication.Bluetooth.Core216
217**参数:**
218
219| 参数名      | 类型     | 必填   | 说明                                    |
220| -------- | ------ | ---- | ------------------------------------- |
221| deviceId | string | 是    | 表示要删除的远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
222| callback | AsyncCallback<void> | 是    | 回调函数。当删除远程配对设备成功,err为undefined,否则为错误对象。   |
223
224**错误码**:
225
226以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
227
228| 错误码ID | 错误信息 |
229| -------- | ---------------------------- |
230|2900001 | Service stopped.                         |
231|2900003 | Bluetooth switch is off.                 |
232|2900099 | Operation failed.                        |
233
234**示例:**
235
236```js
237import { BusinessError } from '@ohos.base';
238try {
239    connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
240} catch (err) {
241    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
242}
243```
244
245
246## connection.cancelPairingDevice
247
248cancelPairingDevice(deviceId: string): Promise<void>
249
250删除正在配对中的远程设备。
251
252**系统接口**:此接口为系统接口。
253
254**需要权限**:ohos.permission.ACCESS_BLUETOOTH
255
256**系统能力**:SystemCapability.Communication.Bluetooth.Core257
258**参数:**
259
260| 参数名      | 类型     | 必填   | 说明                                    |
261| -------- | ------ | ---- | ------------------------------------- |
262| deviceId | string | 是    | 表示要删除的远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
263
264**返回值:**
265
266| 类型                  | 说明            |
267| ------------------- | ------------- |
268| Promise<void> | 返回promise对象。 |
269
270**错误码**:
271
272以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
273
274| 错误码ID | 错误信息 |
275| -------- | ---------------------------- |
276|2900001 | Service stopped.                         |
277|2900003 | Bluetooth switch is off.                 |
278|2900099 | Operation failed.                        |
279
280**示例:**
281
282```js
283import { BusinessError } from '@ohos.base';
284try {
285    connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
286} catch (err) {
287    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
288}
289```
290
291
292## connection.getLocalProfileUuids
293
294getLocalProfileUuids(callback: AsyncCallback<Array<ProfileUuids>>): void
295
296获取本地设备的profile UUID。
297
298**系统接口**:此接口为系统接口。
299
300**需要权限**:ohos.permission.ACCESS_BLUETOOTH
301
302**系统能力**:SystemCapability.Communication.Bluetooth.Core303
304**参数:**
305
306| 参数名      | 类型     | 必填   | 说明                                  |
307| -------- | ------ | ---- | ----------------------------------- |
308| callback | AsyncCallback<Array<[ProfileUuids](js-apis-bluetooth-constant-sys.md#profileuuids)>> | 是    | 回调函数。当获取UUID成功,err为undefined,否则为错误对象。 |
309
310**错误码**:
311
312以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
313
314| 错误码ID | 错误信息 |
315| -------- | ---------------------------- |
316|2900001 | Service stopped.                         |
317|2900003 | Bluetooth switch is off.                 |
318|2900099 | Operation failed.                        |
319
320**示例:**
321
322```js
323import { BusinessError } from '@ohos.base';
324try {
325    connection.getLocalProfileUuids('XX:XX:XX:XX:XX:XX', (err: BusinessError, data: Array<connection.ProfileUuids>) => {
326        console.info('getLocalProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
327    });
328} catch (err) {
329    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
330}
331```
332
333
334## connection.getLocalProfileUuids
335
336getLocalProfileUuids(): Promise&lt;Array&lt;ProfileUuids&gt;&gt;
337
338获取本地设备的profile UUID。
339
340**系统接口**:此接口为系统接口。
341
342**需要权限**:ohos.permission.ACCESS_BLUETOOTH
343
344**系统能力**:SystemCapability.Communication.Bluetooth.Core345
346**返回值:**
347
348| 类型                  | 说明            |
349| ------------------- | ------------- |
350|   Promise&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant-sys.md#profileuuids)&gt;&gt; | 返回promise对象。 |
351
352**错误码**:
353
354以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
355
356| 错误码ID | 错误信息 |
357| -------- | ---------------------------- |
358|2900001 | Service stopped.                         |
359|2900003 | Bluetooth switch is off.                 |
360|2900099 | Operation failed.                        |
361
362**示例:**
363
364```js
365import { BusinessError } from '@ohos.base';
366try {
367    connection.getLocalProfileUuids('XX:XX:XX:XX:XX:XX').then(() => {
368        console.info('getLocalProfileUuids');
369    }, (err: BusinessError) => {
370        console.error('getLocalProfileUuids: errCode' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
371    });
372} catch (err) {
373    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
374}
375```
376
377
378## connection.getRemoteProfileUuids
379
380getRemoteProfileUuids(deviceId: string, callback: AsyncCallback&lt;Array&lt;ProfileUuids&gt;&gt;): void
381
382获取对端蓝牙设备支持的Profile UUID。
383
384**系统接口**:此接口为系统接口。
385
386**需要权限**:ohos.permission.ACCESS_BLUETOOTH
387
388**系统能力**:SystemCapability.Communication.Bluetooth.Core389
390**参数:**
391
392| 参数名      | 类型     | 必填   | 说明                                  |
393| -------- | ------ | ---- | ----------------------------------- |
394| deviceId | string | 是    | 表示配对的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
395| callback | AsyncCallback&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant-sys.md#profileuuids)&gt;&gt; | 是    | 回调函数。当获取UUID成功,err为undefined,否则为错误对象。 |
396
397**错误码**:
398
399以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
400
401| 错误码ID | 错误信息 |
402| -------- | ---------------------------- |
403|2900001 | Service stopped.                         |
404|2900003 | Bluetooth switch is off.                 |
405|2900099 | Operation failed.                        |
406
407**示例:**
408
409```js
410import { BusinessError } from '@ohos.base';
411try {
412    connection.getRemoteProfileUuids('XX:XX:XX:XX:XX:XX', (err: BusinessError, data: Array<connection.ProfileUuids>) => {
413        console.info('getRemoteProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
414    });
415} catch (err) {
416    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
417}
418
419```
420
421
422## connection.getRemoteProfileUuids
423
424getRemoteProfileUuids(deviceId: string): Promise&lt;Array&lt;ProfileUuids&gt;&gt;
425
426获取对端蓝牙设备支持的Profile UUID。
427
428**系统接口**:此接口为系统接口。
429
430**需要权限**:ohos.permission.ACCESS_BLUETOOTH
431
432**系统能力**:SystemCapability.Communication.Bluetooth.Core433
434**参数:**
435
436| 参数名      | 类型     | 必填   | 说明                                  |
437| -------- | ------ | ---- | ----------------------------------- |
438| deviceId | string | 是    | 表示配对的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
439
440**返回值:**
441
442| 类型                  | 说明            |
443| ------------------- | ------------- |
444|   Promise&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant-sys.md#profileuuids)&gt;&gt; | 返回promise对象。 |
445
446**错误码**:
447
448以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
449
450| 错误码ID | 错误信息 |
451| -------- | ---------------------------- |
452|2900001 | Service stopped.                         |
453|2900003 | Bluetooth switch is off.                 |
454|2900099 | Operation failed.                        |
455
456**示例:**
457
458```js
459import { BusinessError } from '@ohos.base';
460try {
461    connection.getRemoteProfileUuids('XX:XX:XX:XX:XX:XX').then(() => {
462        console.info('getRemoteProfileUuids');
463    }, (err: BusinessError) => {
464        console.error('getRemoteProfileUuids: errCode' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
465    });
466} catch (err) {
467    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
468}
469```
470
471
472## connection.connectAllowedProfiles<sup>11+</sup>
473
474connectAllowedProfiles(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
475
476连接远端设备所有允许连接的profiles。
477
478**系统接口**:此接口为系统接口。
479
480**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
481
482**系统能力**:SystemCapability.Communication.Bluetooth.Core483
484**参数:**
485
486| 参数名      | 类型     | 必填   | 说明                                  |
487| -------- | ------ | ---- | ----------------------------------- |
488| deviceId | string | 是    | 表示连接的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
489| callback | AsyncCallback&lt;void&gt; | 是    | 以callback形式异步返回结果。当发起连接成功,err为undefined,否则为错误对象。   |
490
491**错误码**:
492
493以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
494
495| 错误码ID | 错误信息 |
496| -------- | ---------------------------- |
497|201     | Permission denied.                       |
498|202     | Non-system applications are not allowed to use system APIs.                       |
499|401     | Invalid parameter.                       |
500|801     | Capability not supported.                |
501|2900001 | Service stopped.                         |
502|2900003 | Bluetooth switch is off.                 |
503|2900099 | Operation failed.                        |
504
505**示例:**
506
507```js
508import { BusinessError } from '@ohos.base';
509try {
510    connection.connectAllowedProfiles('68:13:24:79:4C:8C', (err: BusinessError) => {
511        if (err) {
512            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
513            return;
514        }
515        console.info('connectAllowedProfiles, err: ' + JSON.stringify(err));
516    });
517} catch (err) {
518    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
519}
520```
521
522
523## connection.connectAllowedProfiles<sup>11+</sup>
524
525connectAllowedProfiles(deviceId: string): Promise&lt;void&gt;
526
527连接远端设备所有允许连接的profiles。
528
529**系统接口**:此接口为系统接口。
530
531**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
532
533**系统能力**:SystemCapability.Communication.Bluetooth.Core534
535**参数:**
536
537| 参数名      | 类型     | 必填   | 说明                                  |
538| -------- | ------ | ---- | ----------------------------------- |
539| deviceId | string | 是    | 表示连接的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
540
541**返回值:**
542
543| 类型                                              | 说明                |
544| ------------------------------------------------- | ------------------- |
545| Promise&lt;void&gt; | 以Promise形式返回连接profiles的结果,返回true为成功,false为失败。 |
546
547**错误码**:
548
549以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
550
551| 错误码ID | 错误信息 |
552| -------- | ---------------------------- |
553|201     | Permission denied.                       |
554|202     | Non-system applications are not allowed to use system APIs.                       |
555|401     | Invalid parameter.                       |
556|801     | Capability not supported.                |
557|2900001 | Service stopped.                         |
558|2900003 | Bluetooth switch is off.                 |
559|2900099 | Operation failed.                        |
560
561**示例:**
562
563```js
564import { BusinessError } from '@ohos.base';
565try {
566    connection.connectAllowedProfiles('68:13:24:79:4C:8C').then(() => {
567        console.info('connectAllowedProfiles');
568    }, (err: BusinessError) => {
569        console.error('connectAllowedProfiles:errCode' + err.code + ', errMessage: ' + err.message);
570    });
571} catch (err) {
572    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
573}
574```
575
576
577## connection.disconnectAllowedProfiles<sup>11+</sup>
578
579disconnectAllowedProfiles(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
580
581断开远端设备所有连接的profiles。
582
583**系统接口**:此接口为系统接口。
584
585**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
586
587**系统能力**:SystemCapability.Communication.Bluetooth.Core588
589**参数:**
590
591| 参数名      | 类型     | 必填   | 说明                                  |
592| -------- | ------ | ---- | ----------------------------------- |
593| deviceId | string | 是    | 表示断开的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
594| callback | AsyncCallback&lt;void&gt; | 是    | 以callback形式异步返回结果。当发起断开成功,err为undefined,否则为错误对象。   |
595
596**错误码**:
597
598以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
599
600| 错误码ID | 错误信息 |
601| -------- | ---------------------------- |
602|201     | Permission denied.                       |
603|202     | Non-system applications are not allowed to use system APIs.                       |
604|401     | Invalid parameter.                       |
605|801     | Capability not supported.                |
606|2900001 | Service stopped.                         |
607|2900003 | Bluetooth switch is off.                 |
608|2900099 | Operation failed.                        |
609
610**示例:**
611
612```js
613import { BusinessError } from '@ohos.base';
614try {
615    connection.disconnectAllowedProfiles('68:13:24:79:4C:8C', (err: BusinessError) => {
616        if (err) {
617            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
618            return;
619        }
620        console.info('disconnectAllowedProfiles, err: ' + JSON.stringify(err));
621    });
622} catch (err) {
623    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
624}
625```
626
627
628## connection.disconnectAllowedProfiles<sup>11+</sup>
629
630disconnectAllowedProfiles(deviceId: string): Promise&lt;void&gt;
631
632断开远端设备所有连接的profiles。
633
634**系统接口**:此接口为系统接口。
635
636**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
637
638**系统能力**:SystemCapability.Communication.Bluetooth.Core639
640**参数:**
641
642| 参数名      | 类型     | 必填   | 说明                                  |
643| -------- | ------ | ---- | ----------------------------------- |
644| deviceId | string | 是    | 表示断开的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
645
646**返回值:**
647
648| 类型                                              | 说明                |
649| ------------------------------------------------- | ------------------- |
650| Promise&lt;void&gt; | 以Promise形式返回断开profiles的结果,返回true为成功,false为失败。 |
651
652**错误码**:
653
654以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
655
656| 错误码ID | 错误信息 |
657| -------- | ---------------------------- |
658|201     | Permission denied.                       |
659|202     | Non-system applications are not allowed to use system APIs.                       |
660|401     | Invalid parameter.                       |
661|801     | Capability not supported.                |
662|2900001 | Service stopped.                         |
663|2900003 | Bluetooth switch is off.                 |
664|2900099 | Operation failed.                        |
665
666**示例:**
667
668```js
669import { BusinessError } from '@ohos.base';
670try {
671    connection.disconnectAllowedProfiles('68:13:24:79:4C:8C').then(() => {
672        console.info('disconnectAllowedProfiles');
673    }, (err: BusinessError) => {
674        console.error('disconnectAllowedProfiles:errCode' + err.code + ', errMessage: ' + err.message);
675    });
676} catch (err) {
677    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
678}
679```
680
681
682## connection.getRemoteProductId<sup>11+</sup>
683
684getRemoteProductId(deviceId: string): string
685
686获取对端蓝牙设备的Product ID。
687
688**系统接口**:此接口为系统接口。
689
690**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
691
692**系统能力**:SystemCapability.Communication.Bluetooth.Core693
694**参数:**
695
696| 参数名      | 类型     | 必填   | 说明                                |
697| -------- | ------ | ---- | --------------------------------- |
698| deviceId | string | 是    | 表示远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
699
700**返回值:**
701
702| 类型     | 说明            |
703| ------ | ------------- |
704| string | 以字符串格式返回设备Product ID。 |
705
706**错误码**:
707
708以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
709
710| 错误码ID | 错误信息 |
711| -------- | ---------------------------- |
712|2900001 | Service stopped.                         |
713|2900003 | Bluetooth switch is off.                 |
714|2900099 | Operation failed.                        |
715
716**示例:**
717
718```js
719import connection from '@ohos.bluetooth.connection';
720try {
721  let remoteDeviceProductId = connection.getRemoteProductId('XX:XX:XX:XX:XX:XX');
722} catch (err) {
723  console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
724}
725```
726
727
728## PinRequiredParam
729
730描述配对请求参数。
731
732**系统能力**:SystemCapability.Communication.Bluetooth.Core733
734| 名称       | 类型   | 可读   | 可写   | 说明          |
735| -------- | ------ | ---- | ---- | ----------- |
736| pinType | [PinType](#pintype) | 是    | 否    | 表示要配对的设备类型。<br/>此接口为系统接口。   |
737
738
739
740## PinType
741
742枚举,蓝牙配对类型。
743
744**系统接口:** 此接口为系统接口。
745
746**系统能力**:SystemCapability.Communication.Bluetooth.Core747
748| 名称                               | 值    | 说明              |
749| -------------------------------- | ------ | --------------- |
750| PIN_TYPE_ENTER_PIN_CODE | 0 | 用户需要输入对端设备上显示的PIN码。<br/>此接口为系统接口。 |
751| PIN_TYPE_ENTER_PASSKEY  | 1 | 用户需要输入对端设备上显示的PASSKEY。<br/>此接口为系统接口。  |
752| PIN_TYPE_CONFIRM_PASSKEY  | 2 | 用户需要确认本地设备上显示的PASSKEY。<br/>此接口为系统接口。  |
753| PIN_TYPE_NO_PASSKEY_CONSENT  | 3 | 无PASSKEY,用户需要接受或拒绝配对请求。<br/>此接口为系统接口。  |
754| PIN_TYPE_NOTIFY_PASSKEY   | 4 | 本地设备显示PASSKEY,用户需要在对端设备上输入该PASSKEY。<br/>此接口为系统接口。  |
755| PIN_TYPE_DISPLAY_PIN_CODE    | 5 | bluetooth 2.0设备,用户需要输入对端设备上显示的PIN码。<br/>此接口为系统接口。  |
756| PIN_TYPE_OOB_CONSENT    | 6 | 用户需要接受或拒绝OOB配对请求。<br/>此接口为系统接口。  |
757| PIN_TYPE_PIN_16_DIGITS    | 7 | 用户需要输入对端设备上显示的16位PIN码。<br/>此接口为系统接口。  |