1e41f4b71Sopenharmony_ci# @ohos.bluetooth.connection (蓝牙connection模块)(系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciconnection模块提供了对蓝牙操作和管理的方法。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.connection (蓝牙connection模块)](js-apis-bluetooth-connection.md)
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## 导入模块
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```js
14e41f4b71Sopenharmony_ciimport { connection } from '@kit.ConnectivityKit';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci## connection.pairCredibleDevice
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_cipairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback<void>): void
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci向可信的远端设备发起蓝牙配对。通过非蓝牙扫描的方式(例如NFC等)获取到外设的地址,可以通过该接口发起配对。使用Callback异步回调。
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci**参数:**
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
33e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
34e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示配对的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
35e41f4b71Sopenharmony_ci| transport | [BluetoothTransport](js-apis-bluetooth-connection.md#bluetoothtransport) | 是    | 表示设备类型,例如传统蓝牙设备或低功耗蓝牙设备。 |
36e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是    | 回调函数。当发起配对成功,err为undefined,否则为错误对象。   |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**错误码**:
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
43e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
44e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
45e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
46e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
47e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
48e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
49e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
50e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci**示例:**
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci```js
55e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
56e41f4b71Sopenharmony_citry {
57e41f4b71Sopenharmony_ci    connection.pairCredibleDevice('68:13:24:79:4C:8C', connection.BluetoothTransport
58e41f4b71Sopenharmony_ci        .TRANSPORT_BR_EDR, (err: BusinessError) => {
59e41f4b71Sopenharmony_ci        if (err) {
60e41f4b71Sopenharmony_ci            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
61e41f4b71Sopenharmony_ci            return;
62e41f4b71Sopenharmony_ci        }
63e41f4b71Sopenharmony_ci        console.info('pairCredibleDevice, err: ' + JSON.stringify(err));
64e41f4b71Sopenharmony_ci    });
65e41f4b71Sopenharmony_ci} catch (err) {
66e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
67e41f4b71Sopenharmony_ci}
68e41f4b71Sopenharmony_ci```
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci## connection.pairCredibleDevice
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_cipairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise<void>
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci向可信的远端设备发起蓝牙配对。通过非蓝牙扫描的方式(例如NFC等)获取到外设的地址,可以通过该接口发起配对。使用Promise异步回调。
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**参数:**
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
86e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
87e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示配对的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
88e41f4b71Sopenharmony_ci| transport | [BluetoothTransport](js-apis-bluetooth-connection.md#bluetoothtransport) | 是    | 表示设备类型,例如传统蓝牙设备或低功耗蓝牙设备。 |
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**返回值:**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| 类型                                              | 说明                |
93e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------- |
94e41f4b71Sopenharmony_ci| Promise<void> | 返回promise对象。 |
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**错误码**:
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
101e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
102e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
103e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
104e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
105e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
106e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
107e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
108e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci**示例:**
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci```js
113e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
114e41f4b71Sopenharmony_citry {
115e41f4b71Sopenharmony_ci    connection.pairCredibleDevice('68:13:24:79:4C:8C', 0).then(() => {
116e41f4b71Sopenharmony_ci        console.info('PairCredibleDevice');
117e41f4b71Sopenharmony_ci    }, (err: BusinessError) => {
118e41f4b71Sopenharmony_ci        console.error('PairCredibleDevice:errCode' + err.code + ', errMessage: ' + err.message);
119e41f4b71Sopenharmony_ci    });
120e41f4b71Sopenharmony_ci} catch (err) {
121e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
122e41f4b71Sopenharmony_ci}
123e41f4b71Sopenharmony_ci```
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci## connection.cancelPairedDevice
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_cicancelPairedDevice(deviceId: string, callback: AsyncCallback<void>): void
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci删除配对的远程设备。使用Callback异步回调。
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**参数:**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                    |
141e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------- |
142e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示要删除的远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
143e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是    | 回调函数。当删除远程配对设备成功,err为undefined,否则为错误对象。   |
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci**错误码**:
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
150e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
151e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
152e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
153e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
154e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
155e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
156e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
157e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci**示例:**
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci```js
162e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
163e41f4b71Sopenharmony_ci//callback
164e41f4b71Sopenharmony_citry {
165e41f4b71Sopenharmony_ci    connection.cancelPairedDevice('11:22:33:44:55:66', (err: BusinessError) => {
166e41f4b71Sopenharmony_ci        console.info('cancelPairedDevice, device name err:' + JSON.stringify(err));
167e41f4b71Sopenharmony_ci    });
168e41f4b71Sopenharmony_ci} catch (err) {
169e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
170e41f4b71Sopenharmony_ci}
171e41f4b71Sopenharmony_ci```
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci## connection.cancelPairedDevice
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_cicancelPairedDevice(deviceId: string): Promise<void>
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci删除配对的远程设备。使用Promise异步回调。
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci**参数:**
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                    |
189e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------- |
190e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示要删除的远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci**返回值:**
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci| 类型                  | 说明            |
195e41f4b71Sopenharmony_ci| ------------------- | ------------- |
196e41f4b71Sopenharmony_ci| Promise<void> | 返回promise对象。 |
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci**错误码**:
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
203e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
204e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
205e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
206e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
207e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
208e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
209e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
210e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci**示例:**
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ci```js
215e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
216e41f4b71Sopenharmony_ci//promise
217e41f4b71Sopenharmony_citry {
218e41f4b71Sopenharmony_ci    connection.cancelPairedDevice('11:22:33:44:55:66').then(() => {
219e41f4b71Sopenharmony_ci        console.info('cancelPairedDevice');
220e41f4b71Sopenharmony_ci    }, (error: BusinessError) => {
221e41f4b71Sopenharmony_ci        console.info('cancelPairedDevice: errCode:' + error.code + ',errMessage' + error.message);
222e41f4b71Sopenharmony_ci    })
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci} catch (err) {
225e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
226e41f4b71Sopenharmony_ci}
227e41f4b71Sopenharmony_ci```
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci## connection.cancelPairingDevice
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_cicancelPairingDevice(deviceId: string, callback: AsyncCallback<void>): void
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci删除正在配对中的远程设备。使用Callback异步回调。
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**参数:**
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                    |
245e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------- |
246e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示要删除的远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
247e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是    | 回调函数。当删除远程配对设备成功,err为undefined,否则为错误对象。   |
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci**错误码**:
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
254e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
255e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
256e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
257e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
258e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
259e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
260e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
261e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci**示例:**
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci```js
266e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
267e41f4b71Sopenharmony_citry {
268e41f4b71Sopenharmony_ci    connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
269e41f4b71Sopenharmony_ci} catch (err) {
270e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
271e41f4b71Sopenharmony_ci}
272e41f4b71Sopenharmony_ci```
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci## connection.cancelPairingDevice
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_cicancelPairingDevice(deviceId: string): Promise<void>
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci删除正在配对中的远程设备。使用Promise异步回调。
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core286e41f4b71Sopenharmony_ci
287e41f4b71Sopenharmony_ci**参数:**
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                    |
290e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------- |
291e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示要删除的远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci**返回值:**
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci| 类型                  | 说明            |
296e41f4b71Sopenharmony_ci| ------------------- | ------------- |
297e41f4b71Sopenharmony_ci| Promise<void> | 返回promise对象。 |
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci**错误码**:
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
304e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
305e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
306e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
307e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
308e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
309e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
310e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
311e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci**示例:**
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci```js
316e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
317e41f4b71Sopenharmony_citry {
318e41f4b71Sopenharmony_ci    connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
319e41f4b71Sopenharmony_ci} catch (err) {
320e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
321e41f4b71Sopenharmony_ci}
322e41f4b71Sopenharmony_ci```
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci## connection.getLocalProfileUuids
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_cigetLocalProfileUuids(callback: AsyncCallback<Array<ProfileUuids>>): void
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci获取本地设备的profile UUID。使用Callback异步回调。
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ci**参数:**
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
340e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
341e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)>> | 是    | 回调函数。当获取UUID成功,err为undefined,否则为错误对象。 |
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci**错误码**:
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
348e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
349e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
350e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
351e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.             |
352e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
353e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
354e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
355e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci**示例:**
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci```js
360e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
361e41f4b71Sopenharmony_citry {
362e41f4b71Sopenharmony_ci    connection.getLocalProfileUuids((err: BusinessError, data: Array<connection.ProfileUuids>) => {
363e41f4b71Sopenharmony_ci        console.info('getLocalProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
364e41f4b71Sopenharmony_ci    });
365e41f4b71Sopenharmony_ci} catch (err) {
366e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
367e41f4b71Sopenharmony_ci}
368e41f4b71Sopenharmony_ci```
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci## connection.getLocalProfileUuids
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_cigetLocalProfileUuids(): Promise&lt;Array&lt;ProfileUuids&gt;&gt;
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci获取本地设备的profile UUID。使用Promise异步回调。
376e41f4b71Sopenharmony_ci
377e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ci**返回值:**
384e41f4b71Sopenharmony_ci
385e41f4b71Sopenharmony_ci| 类型                  | 说明            |
386e41f4b71Sopenharmony_ci| ------------------- | ------------- |
387e41f4b71Sopenharmony_ci|   Promise&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | 返回promise对象。 |
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci**错误码**:
390e41f4b71Sopenharmony_ci
391e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
392e41f4b71Sopenharmony_ci
393e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
394e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
395e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
396e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
397e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.           |
398e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
399e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
400e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
401e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci**示例:**
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci```js
406e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
407e41f4b71Sopenharmony_citry {
408e41f4b71Sopenharmony_ci    connection.getLocalProfileUuids().then(() => {
409e41f4b71Sopenharmony_ci        console.info('getLocalProfileUuids');
410e41f4b71Sopenharmony_ci    }, (err: BusinessError) => {
411e41f4b71Sopenharmony_ci        console.error('getLocalProfileUuids: errCode' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
412e41f4b71Sopenharmony_ci    });
413e41f4b71Sopenharmony_ci} catch (err) {
414e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
415e41f4b71Sopenharmony_ci}
416e41f4b71Sopenharmony_ci```
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci## connection.connectAllowedProfiles<sup>11+</sup>
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ciconnectAllowedProfiles(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci连接远端设备所有允许连接的profiles。使用Callback异步回调。
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci**参数:**
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
434e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
435e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示连接的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
436e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | 是    | 以callback形式异步返回结果。当发起连接成功,err为undefined,否则为错误对象。   |
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_ci**错误码**:
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
443e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
444e41f4b71Sopenharmony_ci|201     | Permission denied.                       |
445e41f4b71Sopenharmony_ci|202     | Non-system applications are not allowed to use system APIs.                       |
446e41f4b71Sopenharmony_ci|401     | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                       |
447e41f4b71Sopenharmony_ci|801     | Capability not supported.                |
448e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
449e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
450e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
451e41f4b71Sopenharmony_ci
452e41f4b71Sopenharmony_ci**示例:**
453e41f4b71Sopenharmony_ci
454e41f4b71Sopenharmony_ci```js
455e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
456e41f4b71Sopenharmony_citry {
457e41f4b71Sopenharmony_ci    connection.connectAllowedProfiles('68:13:24:79:4C:8C', (err: BusinessError) => {
458e41f4b71Sopenharmony_ci        if (err) {
459e41f4b71Sopenharmony_ci            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
460e41f4b71Sopenharmony_ci            return;
461e41f4b71Sopenharmony_ci        }
462e41f4b71Sopenharmony_ci        console.info('connectAllowedProfiles, err: ' + JSON.stringify(err));
463e41f4b71Sopenharmony_ci    });
464e41f4b71Sopenharmony_ci} catch (err) {
465e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
466e41f4b71Sopenharmony_ci}
467e41f4b71Sopenharmony_ci```
468e41f4b71Sopenharmony_ci
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci## connection.connectAllowedProfiles<sup>11+</sup>
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ciconnectAllowedProfiles(deviceId: string): Promise&lt;void&gt;
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci连接远端设备所有允许连接的profiles。使用Promise异步回调。
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci**参数:**
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
485e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
486e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示连接的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_ci**返回值:**
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ci| 类型                                              | 说明                |
491e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------- |
492e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 以Promise形式返回连接profiles的结果,返回true为成功,false为失败。 |
493e41f4b71Sopenharmony_ci
494e41f4b71Sopenharmony_ci**错误码**:
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
499e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
500e41f4b71Sopenharmony_ci|201     | Permission denied.                       |
501e41f4b71Sopenharmony_ci|202     | Non-system applications are not allowed to use system APIs.                       |
502e41f4b71Sopenharmony_ci|401     | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                       |
503e41f4b71Sopenharmony_ci|801     | Capability not supported.                |
504e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
505e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
506e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci**示例:**
509e41f4b71Sopenharmony_ci
510e41f4b71Sopenharmony_ci```js
511e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
512e41f4b71Sopenharmony_citry {
513e41f4b71Sopenharmony_ci    connection.connectAllowedProfiles('68:13:24:79:4C:8C').then(() => {
514e41f4b71Sopenharmony_ci        console.info('connectAllowedProfiles');
515e41f4b71Sopenharmony_ci    }, (err: BusinessError) => {
516e41f4b71Sopenharmony_ci        console.error('connectAllowedProfiles:errCode' + err.code + ', errMessage: ' + err.message);
517e41f4b71Sopenharmony_ci    });
518e41f4b71Sopenharmony_ci} catch (err) {
519e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
520e41f4b71Sopenharmony_ci}
521e41f4b71Sopenharmony_ci```
522e41f4b71Sopenharmony_ci
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci## connection.disconnectAllowedProfiles<sup>11+</sup>
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_cidisconnectAllowedProfiles(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_ci断开远端设备所有连接的profiles。使用Callback异步回调。
529e41f4b71Sopenharmony_ci
530e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
531e41f4b71Sopenharmony_ci
532e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core535e41f4b71Sopenharmony_ci
536e41f4b71Sopenharmony_ci**参数:**
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
539e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
540e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示断开的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
541e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | 是    | 以callback形式异步返回结果。当发起断开成功,err为undefined,否则为错误对象。   |
542e41f4b71Sopenharmony_ci
543e41f4b71Sopenharmony_ci**错误码**:
544e41f4b71Sopenharmony_ci
545e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
548e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
549e41f4b71Sopenharmony_ci|201     | Permission denied.                       |
550e41f4b71Sopenharmony_ci|202     | Non-system applications are not allowed to use system APIs.                       |
551e41f4b71Sopenharmony_ci|401     | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                       |
552e41f4b71Sopenharmony_ci|801     | Capability not supported.                |
553e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
554e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
555e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
556e41f4b71Sopenharmony_ci
557e41f4b71Sopenharmony_ci**示例:**
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ci```js
560e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
561e41f4b71Sopenharmony_citry {
562e41f4b71Sopenharmony_ci    connection.disconnectAllowedProfiles('68:13:24:79:4C:8C', (err: BusinessError) => {
563e41f4b71Sopenharmony_ci        if (err) {
564e41f4b71Sopenharmony_ci            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
565e41f4b71Sopenharmony_ci            return;
566e41f4b71Sopenharmony_ci        }
567e41f4b71Sopenharmony_ci        console.info('disconnectAllowedProfiles, err: ' + JSON.stringify(err));
568e41f4b71Sopenharmony_ci    });
569e41f4b71Sopenharmony_ci} catch (err) {
570e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
571e41f4b71Sopenharmony_ci}
572e41f4b71Sopenharmony_ci```
573e41f4b71Sopenharmony_ci
574e41f4b71Sopenharmony_ci
575e41f4b71Sopenharmony_ci## connection.disconnectAllowedProfiles<sup>11+</sup>
576e41f4b71Sopenharmony_ci
577e41f4b71Sopenharmony_cidisconnectAllowedProfiles(deviceId: string): Promise&lt;void&gt;
578e41f4b71Sopenharmony_ci
579e41f4b71Sopenharmony_ci断开远端设备所有连接的profiles。使用Promise异步回调。
580e41f4b71Sopenharmony_ci
581e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
582e41f4b71Sopenharmony_ci
583e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci**参数:**
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
590e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
591e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示断开的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ci**返回值:**
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci| 类型                                              | 说明                |
596e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------- |
597e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 以Promise形式返回断开profiles的结果,返回true为成功,false为失败。 |
598e41f4b71Sopenharmony_ci
599e41f4b71Sopenharmony_ci**错误码**:
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
604e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
605e41f4b71Sopenharmony_ci|201     | Permission denied.                       |
606e41f4b71Sopenharmony_ci|202     | Non-system applications are not allowed to use system APIs.                       |
607e41f4b71Sopenharmony_ci|401     | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                       |
608e41f4b71Sopenharmony_ci|801     | Capability not supported.                |
609e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
610e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
611e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
612e41f4b71Sopenharmony_ci
613e41f4b71Sopenharmony_ci**示例:**
614e41f4b71Sopenharmony_ci
615e41f4b71Sopenharmony_ci```js
616e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
617e41f4b71Sopenharmony_citry {
618e41f4b71Sopenharmony_ci    connection.disconnectAllowedProfiles('68:13:24:79:4C:8C').then(() => {
619e41f4b71Sopenharmony_ci        console.info('disconnectAllowedProfiles');
620e41f4b71Sopenharmony_ci    }, (err: BusinessError) => {
621e41f4b71Sopenharmony_ci        console.error('disconnectAllowedProfiles:errCode' + err.code + ', errMessage: ' + err.message);
622e41f4b71Sopenharmony_ci    });
623e41f4b71Sopenharmony_ci} catch (err) {
624e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
625e41f4b71Sopenharmony_ci}
626e41f4b71Sopenharmony_ci```
627e41f4b71Sopenharmony_ci
628e41f4b71Sopenharmony_ci
629e41f4b71Sopenharmony_ci## connection.getRemoteProductId<sup>11+</sup>
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_cigetRemoteProductId(deviceId: string): string
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ci获取对端蓝牙设备的Product ID。
634e41f4b71Sopenharmony_ci
635e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
636e41f4b71Sopenharmony_ci
637e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
638e41f4b71Sopenharmony_ci
639e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core640e41f4b71Sopenharmony_ci
641e41f4b71Sopenharmony_ci**参数:**
642e41f4b71Sopenharmony_ci
643e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                |
644e41f4b71Sopenharmony_ci| -------- | ------ | ---- | --------------------------------- |
645e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远程设备的地址,例如:"XX:XX:XX:XX:XX:XX"。 |
646e41f4b71Sopenharmony_ci
647e41f4b71Sopenharmony_ci**返回值:**
648e41f4b71Sopenharmony_ci
649e41f4b71Sopenharmony_ci| 类型     | 说明            |
650e41f4b71Sopenharmony_ci| ------ | ------------- |
651e41f4b71Sopenharmony_ci| string | 以字符串格式返回设备Product ID。 |
652e41f4b71Sopenharmony_ci
653e41f4b71Sopenharmony_ci**错误码**:
654e41f4b71Sopenharmony_ci
655e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
658e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
659e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
660e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
661e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
662e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
663e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
664e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
665e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
666e41f4b71Sopenharmony_ci
667e41f4b71Sopenharmony_ci**示例:**
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ci```js
670e41f4b71Sopenharmony_citry {
671e41f4b71Sopenharmony_ci  let remoteDeviceProductId = connection.getRemoteProductId('XX:XX:XX:XX:XX:XX');
672e41f4b71Sopenharmony_ci} catch (err) {
673e41f4b71Sopenharmony_ci  console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
674e41f4b71Sopenharmony_ci}
675e41f4b71Sopenharmony_ci```
676e41f4b71Sopenharmony_ci
677e41f4b71Sopenharmony_ci## connection.on('discoveryResult')<sup>12+</sup>
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_cion(type: 'discoveryResult', callback: Callback&lt;Array&lt;DiscoveryResult&gt;&gt;): void
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_ci订阅蓝牙设备发现上报事件。使用Callback异步回调。
682e41f4b71Sopenharmony_ci
683e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.GET_BLUETOOTH_PEERS_MAC
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ci**参数:**
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci| 参数名      | 类型                                  | 必填   | 说明                                     |
692e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | ---- | -------------------------------------- |
693e41f4b71Sopenharmony_ci| type     | string                              | 是    | 填写"discoveryResult"字符串,表示蓝牙设备发现事件。 |
694e41f4b71Sopenharmony_ci| callback | Callback&lt;Array&lt;[DiscoveryResult](#discoveryresult12)&gt;&gt; | 是    | 表示回调函数的入参,发现的设备集合。回调函数由用户创建通过该接口注册。    |
695e41f4b71Sopenharmony_ci
696e41f4b71Sopenharmony_ci**错误码**:
697e41f4b71Sopenharmony_ci
698e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
701e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
702e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
703e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
704e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
705e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
706e41f4b71Sopenharmony_ci
707e41f4b71Sopenharmony_ci**示例:**
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ci```js
710e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
711e41f4b71Sopenharmony_cilet onReceiveEvent: (data: Array<connection.DiscoveryResult>) => void = (data: Array<connection.DiscoveryResult>) => { // data为蓝牙设备扫描结果集合
712e41f4b71Sopenharmony_ci    console.info('bluetooth device find = '+ JSON.stringify(data));
713e41f4b71Sopenharmony_ci}
714e41f4b71Sopenharmony_citry {
715e41f4b71Sopenharmony_ci    connection.on('discoveryResult', onReceiveEvent);
716e41f4b71Sopenharmony_ci} catch (err) {
717e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
718e41f4b71Sopenharmony_ci}
719e41f4b71Sopenharmony_ci```
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ci
722e41f4b71Sopenharmony_ci## connection.off('discoveryResult')<sup>12+</sup>
723e41f4b71Sopenharmony_ci
724e41f4b71Sopenharmony_cioff(type: 'discoveryResult', callback?: Callback&lt;Array&lt;DiscoveryResult&gt;&gt;): void
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ci取消订阅蓝牙设备发现上报事件。
727e41f4b71Sopenharmony_ci
728e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.GET_BLUETOOTH_PEERS_MAC
731e41f4b71Sopenharmony_ci
732e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci**参数:**
735e41f4b71Sopenharmony_ci
736e41f4b71Sopenharmony_ci| 参数名      | 类型                                  | 必填   | 说明                                       |
737e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | ---- | ---------------------------------------- |
738e41f4b71Sopenharmony_ci| type     | string                              | 是    | 填写"discoveryResult"字符串,表示蓝牙设备发现事件。   |
739e41f4b71Sopenharmony_ci| callback | Callback&lt;Array&lt;[DiscoveryResult](#discoveryresult12)&gt;&gt; | 否    | 表示取消订阅蓝牙设备发现事件上报。不填该参数则取消订阅该type对应的所有回调。 |
740e41f4b71Sopenharmony_ci
741e41f4b71Sopenharmony_ci**错误码**:
742e41f4b71Sopenharmony_ci
743e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
744e41f4b71Sopenharmony_ci
745e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
746e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
747e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
748e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
749e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
750e41f4b71Sopenharmony_ci
751e41f4b71Sopenharmony_ci**示例:**
752e41f4b71Sopenharmony_ci
753e41f4b71Sopenharmony_ci```js
754e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
755e41f4b71Sopenharmony_cilet onReceiveEvent: (data: Array<connection.DiscoveryResult>) => void = (data: Array<connection.DiscoveryResult>) => { // data为蓝牙设备扫描结果集合
756e41f4b71Sopenharmony_ci    console.info('bluetooth device find = '+ JSON.stringify(data));
757e41f4b71Sopenharmony_ci}
758e41f4b71Sopenharmony_citry {
759e41f4b71Sopenharmony_ci    connection.on('discoveryResult', onReceiveEvent);
760e41f4b71Sopenharmony_ci    connection.off('discoveryResult', onReceiveEvent);
761e41f4b71Sopenharmony_ci} catch (err) {
762e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
763e41f4b71Sopenharmony_ci}
764e41f4b71Sopenharmony_ci```
765e41f4b71Sopenharmony_ci
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci## connection.setRemoteDeviceType<sup>12+</sup>
768e41f4b71Sopenharmony_ci
769e41f4b71Sopenharmony_cisetRemoteDeviceType(deviceId: string, type: DeviceType): Promise&lt;void&gt;
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci设置蓝牙远端设备自定义类型。使用Promise异步回调。
772e41f4b71Sopenharmony_ci
773e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
774e41f4b71Sopenharmony_ci
775e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
776e41f4b71Sopenharmony_ci
777e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core778e41f4b71Sopenharmony_ci
779e41f4b71Sopenharmony_ci**参数:**
780e41f4b71Sopenharmony_ci
781e41f4b71Sopenharmony_ci| 参数名    | 类型      | 必填   | 说明                               |
782e41f4b71Sopenharmony_ci| ------ | ------- | ---- | -------------------------------- |
783e41f4b71Sopenharmony_ci| deviceId | string  | 是    | 表示远端设备MAC地址,例如:"XX:XX:XX:XX:XX:XX"。 |
784e41f4b71Sopenharmony_ci| type   | [DeviceType](#devicetype12)  | 是    | 表示设备类型。        |
785e41f4b71Sopenharmony_ci
786e41f4b71Sopenharmony_ci**返回值:**
787e41f4b71Sopenharmony_ci
788e41f4b71Sopenharmony_ci| 类型                  | 说明            |
789e41f4b71Sopenharmony_ci| ------------------- | ------------- |
790e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 以Promise形式返回设置蓝牙远端设备类型的结果,设置失败时返回错误码信息。 |
791e41f4b71Sopenharmony_ci
792e41f4b71Sopenharmony_ci**错误码**:
793e41f4b71Sopenharmony_ci
794e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
795e41f4b71Sopenharmony_ci
796e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
797e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
798e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
799e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
800e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
801e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
802e41f4b71Sopenharmony_ci
803e41f4b71Sopenharmony_ci**示例:**
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_ci```js
806e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
807e41f4b71Sopenharmony_ci//promise
808e41f4b71Sopenharmony_citry {
809e41f4b71Sopenharmony_ci    connection.setRemoteDeviceType('11:22:33:44:55:66', connection.DeviceType.DEVICE_TYPE_HEADSET).then(() => {
810e41f4b71Sopenharmony_ci        console.info('setRemoteDeviceType success');
811e41f4b71Sopenharmony_ci    });
812e41f4b71Sopenharmony_ci} catch (err) {
813e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
814e41f4b71Sopenharmony_ci}
815e41f4b71Sopenharmony_ci```
816e41f4b71Sopenharmony_ci
817e41f4b71Sopenharmony_ci
818e41f4b71Sopenharmony_ci## connection.getRemoteDeviceType<sup>12+</sup>
819e41f4b71Sopenharmony_ci
820e41f4b71Sopenharmony_cigetRemoteDeviceType(deviceId: string): Promise&lt;DeviceType&gt;
821e41f4b71Sopenharmony_ci
822e41f4b71Sopenharmony_ci获取蓝牙远端设备自定义类型。使用Promise异步回调。
823e41f4b71Sopenharmony_ci
824e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
825e41f4b71Sopenharmony_ci
826e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
827e41f4b71Sopenharmony_ci
828e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core829e41f4b71Sopenharmony_ci
830e41f4b71Sopenharmony_ci**参数:**
831e41f4b71Sopenharmony_ci
832e41f4b71Sopenharmony_ci| 参数名    | 类型      | 必填   | 说明                               |
833e41f4b71Sopenharmony_ci| ------ | ------- | ---- | -------------------------------- |
834e41f4b71Sopenharmony_ci| deviceId | string  | 是    | 表示远端设备MAC地址,例如:"XX:XX:XX:XX:XX:XX"。 |
835e41f4b71Sopenharmony_ci
836e41f4b71Sopenharmony_ci**返回值:**
837e41f4b71Sopenharmony_ci
838e41f4b71Sopenharmony_ci| 类型                  | 说明         |
839e41f4b71Sopenharmony_ci| ------------------- | ------------- |
840e41f4b71Sopenharmony_ci| Promise&lt;[DeviceType](#devicetype12)&gt; | 以Promise形式返回设置蓝牙远端设备类型的结果,返回值为设备类型。 |
841e41f4b71Sopenharmony_ci
842e41f4b71Sopenharmony_ci**错误码**:
843e41f4b71Sopenharmony_ci
844e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
845e41f4b71Sopenharmony_ci
846e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
847e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
848e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
849e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
850e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
851e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
852e41f4b71Sopenharmony_ci
853e41f4b71Sopenharmony_ci**示例:**
854e41f4b71Sopenharmony_ci
855e41f4b71Sopenharmony_ci```js
856e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
857e41f4b71Sopenharmony_ci//promise
858e41f4b71Sopenharmony_citry {
859e41f4b71Sopenharmony_ci    connection.getRemoteDeviceType('11:22:33:44:55:66').then((data: connection.DeviceType) => {
860e41f4b71Sopenharmony_ci        console.info('getRemoteDeviceType success, DeviceType:' + JSON.stringify(data));
861e41f4b71Sopenharmony_ci    });
862e41f4b71Sopenharmony_ci} catch (err) {
863e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
864e41f4b71Sopenharmony_ci}
865e41f4b71Sopenharmony_ci```
866e41f4b71Sopenharmony_ci
867e41f4b71Sopenharmony_ci
868e41f4b71Sopenharmony_ci## PinRequiredParam
869e41f4b71Sopenharmony_ci
870e41f4b71Sopenharmony_ci描述配对请求参数。
871e41f4b71Sopenharmony_ci
872e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core873e41f4b71Sopenharmony_ci
874e41f4b71Sopenharmony_ci| 名称       | 类型   | 可读   | 可写   | 说明          |
875e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---- | ----------- |
876e41f4b71Sopenharmony_ci| pinType | [PinType](#pintype) | 是    | 否    | 表示要配对的设备类型。<br/>此接口为系统接口。   |
877e41f4b71Sopenharmony_ci
878e41f4b71Sopenharmony_ci## PinType
879e41f4b71Sopenharmony_ci
880e41f4b71Sopenharmony_ci枚举,蓝牙配对类型。
881e41f4b71Sopenharmony_ci
882e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。
883e41f4b71Sopenharmony_ci
884e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core885e41f4b71Sopenharmony_ci
886e41f4b71Sopenharmony_ci| 名称                               | 值    | 说明              |
887e41f4b71Sopenharmony_ci| -------------------------------- | ------ | --------------- |
888e41f4b71Sopenharmony_ci| PIN_TYPE_ENTER_PIN_CODE | 0 | 用户需要输入对端设备上显示的PIN码。<br/>此接口为系统接口。 |
889e41f4b71Sopenharmony_ci| PIN_TYPE_ENTER_PASSKEY  | 1 | 用户需要输入对端设备上显示的PASSKEY。<br/>此接口为系统接口。  |
890e41f4b71Sopenharmony_ci| PIN_TYPE_CONFIRM_PASSKEY  | 2 | 用户需要确认本地设备上显示的PASSKEY。<br/>此接口为系统接口。  |
891e41f4b71Sopenharmony_ci| PIN_TYPE_NO_PASSKEY_CONSENT  | 3 | 无PASSKEY,用户需要接受或拒绝配对请求。<br/>此接口为系统接口。  |
892e41f4b71Sopenharmony_ci| PIN_TYPE_NOTIFY_PASSKEY   | 4 | 本地设备显示PASSKEY,用户需要在对端设备上输入该PASSKEY。<br/>此接口为系统接口。  |
893e41f4b71Sopenharmony_ci| PIN_TYPE_DISPLAY_PIN_CODE    | 5 | bluetooth 2.0设备,用户需要输入对端设备上显示的PIN码。<br/>此接口为系统接口。  |
894e41f4b71Sopenharmony_ci| PIN_TYPE_OOB_CONSENT    | 6 | 用户需要接受或拒绝OOB配对请求。<br/>此接口为系统接口。  |
895e41f4b71Sopenharmony_ci| PIN_TYPE_PIN_16_DIGITS    | 7 | 用户需要输入对端设备上显示的16位PIN码。<br/>此接口为系统接口。  |
896e41f4b71Sopenharmony_ci
897e41f4b71Sopenharmony_ci
898e41f4b71Sopenharmony_ci## DiscoveryResult<sup>12+</sup>
899e41f4b71Sopenharmony_ci
900e41f4b71Sopenharmony_ci描述扫描设备状态参数。
901e41f4b71Sopenharmony_ci
902e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。
903e41f4b71Sopenharmony_ci
904e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core905e41f4b71Sopenharmony_ci
906e41f4b71Sopenharmony_ci| 名称       | 类型   | 可读   | 可写   | 说明          |
907e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---- | ----------- |
908e41f4b71Sopenharmony_ci| deviceId<sup>12+</sup> | string      | 是    | 否    | 表示扫描到的设备ID。<br/>此接口为系统接口。          |
909e41f4b71Sopenharmony_ci| rssi<sup>12+</sup>     | number      | 是    | 否    | 表示扫描到的设备的信号强度。<br/>此接口为系统接口。   |
910e41f4b71Sopenharmony_ci| deviceName<sup>12+</sup>     | string      | 是    | 否    | 表示扫描到的设备的设备名称。<br/>此接口为系统接口。   |
911e41f4b71Sopenharmony_ci| deviceClass<sup>12+</sup>     | DeviceClass      | 是    | 否    | 表示扫描到的设备的设备类别。<br/>此接口为系统接口。   |
912e41f4b71Sopenharmony_ci
913e41f4b71Sopenharmony_ci
914e41f4b71Sopenharmony_ci## DeviceType<sup>12+</sup>
915e41f4b71Sopenharmony_ci
916e41f4b71Sopenharmony_ci枚举,蓝牙远程设备的自定义类型。
917e41f4b71Sopenharmony_ci
918e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。
919e41f4b71Sopenharmony_ci
920e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core921e41f4b71Sopenharmony_ci
922e41f4b71Sopenharmony_ci| 名称                               | 值    | 说明              |
923e41f4b71Sopenharmony_ci| -------------------------------- | ------ | --------------- |
924e41f4b71Sopenharmony_ci| DEVICE_TYPE_DEFAULT<sup>12+</sup> | 0 | 默认设备类型,与原类型一致。<br/>此接口为系统接口。 |
925e41f4b71Sopenharmony_ci| DEVICE_TYPE_CAR<sup>12+</sup>  | 1 | 汽车。<br/>此接口为系统接口。  |
926e41f4b71Sopenharmony_ci| DEVICE_TYPE_HEADSET<sup>12+</sup>  | 2 | 耳机。<br/>此接口为系统接口。  |
927e41f4b71Sopenharmony_ci| DEVICE_TYPE_HEARING<sup>12+</sup>   | 3 | 助听器<br/>此接口为系统接口。  |
928e41f4b71Sopenharmony_ci| DEVICE_TYPE_GLASSES<sup>12+</sup>    | 4 | 眼镜。<br/>此接口为系统接口。  |
929e41f4b71Sopenharmony_ci| DEVICE_TYPE_WATCH<sup>12+</sup>     | 5 | 手表。<br/>此接口为系统接口。  |
930e41f4b71Sopenharmony_ci| DEVICE_TYPE_SPEAKER<sup>12+</sup>     | 6 | 音响。<br/>此接口为系统接口。  |
931e41f4b71Sopenharmony_ci| DEVICE_TYPE_OTHERS<sup>12+</sup>     | 7 | 其他设备。<br/>此接口为系统接口。  |
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ci
934e41f4b71Sopenharmony_ci## BatteryInfo<sup>12+</sup>
935e41f4b71Sopenharmony_ci
936e41f4b71Sopenharmony_ci描述电量信息的内容。
937e41f4b71Sopenharmony_ci
938e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core939e41f4b71Sopenharmony_ci
940e41f4b71Sopenharmony_ci| 名称       | 类型   | 可读   | 可写   | 说明          |
941e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---- | ----------- |
942e41f4b71Sopenharmony_ci| deviceId | string | 是    | 否    | 表示远端设备的MAC地址。<br/>此接口为系统接口。 |
943e41f4b71Sopenharmony_ci
944