1e41f4b71Sopenharmony_ci# @ohos.bluetooth.wearDetection(蓝牙佩戴检测模块)(系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci佩戴检测模块提供了获取蓝牙音频设备(如蓝牙耳机)是否支持佩戴检测、是否开启佩戴检测的方法。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> 本模块为系统接口。
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci## 导入模块
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci```js
15e41f4b71Sopenharmony_ciimport { wearDetection } from '@kit.ConnectivityKit';
16e41f4b71Sopenharmony_ci```
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## wearDetection.enableWearDetection<sup>11+</sup>
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_cienableWearDetection(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci使能佩戴检测。使用Callback异步回调。
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**参数:**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
34e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
35e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
36e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | 是    | 通过注册回调函数获取使能佩戴检测的结果。如果成功,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_citry {
56e41f4b71Sopenharmony_ci    wearDetection.enableWearDetection('XX:XX:XX:XX:XX:XX', (err) => {
57e41f4b71Sopenharmony_ci        if (err) {
58e41f4b71Sopenharmony_ci            console.error("enableWearDetection error");
59e41f4b71Sopenharmony_ci        }
60e41f4b71Sopenharmony_ci    });
61e41f4b71Sopenharmony_ci} catch (err) {
62e41f4b71Sopenharmony_ci    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
63e41f4b71Sopenharmony_ci}
64e41f4b71Sopenharmony_ci```
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci## wearDetection.enableWearDetection<sup>11+</sup>
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_cienableWearDetection(deviceId: string): Promise&lt;void&gt;
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci使能佩戴检测。使用Promise异步回调。
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**参数:**
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
81e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
82e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**返回值:**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| 类型                            | 说明         |
87e41f4b71Sopenharmony_ci| ----------------------------- | ---------- |
88e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 以Promise的形式返回结果。如果成功,err为undefined,否则为错误对象。 |
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**错误码**:
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
95e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
96e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
97e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
98e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
99e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
100e41f4b71Sopenharmony_ci|2900001 | Service stopped.               |
101e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.       |
102e41f4b71Sopenharmony_ci|2900099 | Operation failed.              |
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**示例:**
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci```js
107e41f4b71Sopenharmony_citry {
108e41f4b71Sopenharmony_ci    wearDetection.enableWearDetection('XX:XX:XX:XX:XX:XX').then(() => {
109e41f4b71Sopenharmony_ci        console.info("enableWearDetection");
110e41f4b71Sopenharmony_ci    });
111e41f4b71Sopenharmony_ci} catch (err) {
112e41f4b71Sopenharmony_ci    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
113e41f4b71Sopenharmony_ci}
114e41f4b71Sopenharmony_ci```
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci## wearDetection.disableWearDetection<sup>11+</sup>
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_cidisableWearDetection(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci禁用佩戴检测。使用Callback异步回调。
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**参数:**
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
131e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
132e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
133e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | 是    | 通过注册回调函数获取禁用佩戴检测的结果。如果成功,err为undefined,否则为错误对象。 |
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**错误码**:
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
140e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
141e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
142e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
143e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
144e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
145e41f4b71Sopenharmony_ci|2900001 | Service stopped.               |
146e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.       |
147e41f4b71Sopenharmony_ci|2900099 | Operation failed.              |
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci**示例:**
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci```js
152e41f4b71Sopenharmony_citry {
153e41f4b71Sopenharmony_ci    wearDetection.disableWearDetection('XX:XX:XX:XX:XX:XX', (err) => {
154e41f4b71Sopenharmony_ci        if (err) {
155e41f4b71Sopenharmony_ci            console.error("disableWearDetection error");
156e41f4b71Sopenharmony_ci        }
157e41f4b71Sopenharmony_ci    });
158e41f4b71Sopenharmony_ci} catch (err) {
159e41f4b71Sopenharmony_ci    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
160e41f4b71Sopenharmony_ci}
161e41f4b71Sopenharmony_ci```
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci## wearDetection.disableWearDetection<sup>11+</sup>
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_cidisableWearDetection(deviceId: string): Promise&lt;void&gt;
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci禁用佩戴检测。使用Promise异步回调。
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci**参数:**
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
178e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
179e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci**返回值:**
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci| 类型                            | 说明         |
184e41f4b71Sopenharmony_ci| ----------------------------- | ---------- |
185e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 以Promise的形式返回结果。如果成功,err为undefined,否则为错误对象。 |
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci**错误码**:
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
192e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
193e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
194e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
195e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
196e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
197e41f4b71Sopenharmony_ci|2900001 | Service stopped.               |
198e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.       |
199e41f4b71Sopenharmony_ci|2900099 | Operation failed.              |
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci**示例:**
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci```js
204e41f4b71Sopenharmony_citry {
205e41f4b71Sopenharmony_ci    wearDetection.disableWearDetection('XX:XX:XX:XX:XX:XX').then(() => {
206e41f4b71Sopenharmony_ci        console.info("disableWearDetection");
207e41f4b71Sopenharmony_ci    });
208e41f4b71Sopenharmony_ci} catch (err) {
209e41f4b71Sopenharmony_ci    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
210e41f4b71Sopenharmony_ci}
211e41f4b71Sopenharmony_ci```
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci## wearDetection.isWearDetectionSupported<sup>11+</sup>
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ciisWearDetectionSupported(deviceId: string, callback: AsyncCallback&lt;boolean&gt;): void
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci获取设备是否支持佩戴检测。使用Callback异步回调。
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci**参数:**
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
228e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
229e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
230e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;boolean&gt; | 是    | 通过注册回调函数获取设备是否支持佩戴检测。如果成功,值在supported中返回。 |
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci**错误码**:
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
237e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
238e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
239e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
240e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
241e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
242e41f4b71Sopenharmony_ci|2900001 | Service stopped.               |
243e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.       |
244e41f4b71Sopenharmony_ci|2900099 | Operation failed.              |
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci**示例:**
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci```js
249e41f4b71Sopenharmony_citry {
250e41f4b71Sopenharmony_ci    wearDetection.isWearDetectionSupported('XX:XX:XX:XX:XX:XX', (err, supported) => {
251e41f4b71Sopenharmony_ci        console.info('device support wear detection ' + supported);
252e41f4b71Sopenharmony_ci    });
253e41f4b71Sopenharmony_ci} catch (err) {
254e41f4b71Sopenharmony_ci    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
255e41f4b71Sopenharmony_ci}
256e41f4b71Sopenharmony_ci```
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci## wearDetection.isWearDetectionSupported<sup>11+</sup>
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ciisWearDetectionSupported(deviceId: string): Promise&lt;boolean&gt;
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci获取设备是否支持佩戴检测。使用Promise异步回调。
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ci**参数:**
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
273e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
274e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci**返回值:**
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci| 类型                            | 说明         |
279e41f4b71Sopenharmony_ci| ----------------------------- | ---------- |
280e41f4b71Sopenharmony_ci| Promise&lt;boolean&gt; | 以Promise的形式获取设备是否支持佩戴检测。如果成功,值在supported中返回。 |
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci**错误码**:
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
287e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
288e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
289e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
290e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
291e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
292e41f4b71Sopenharmony_ci|2900001 | Service stopped.               |
293e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.       |
294e41f4b71Sopenharmony_ci|2900099 | Operation failed.              |
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ci**示例:**
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci```js
299e41f4b71Sopenharmony_citry {
300e41f4b71Sopenharmony_ci    wearDetection.isWearDetectionSupported('XX:XX:XX:XX:XX:XX').then((supported) => {
301e41f4b71Sopenharmony_ci        console.info('device support wear detection ' + supported);
302e41f4b71Sopenharmony_ci    });
303e41f4b71Sopenharmony_ci} catch (err) {
304e41f4b71Sopenharmony_ci    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
305e41f4b71Sopenharmony_ci}
306e41f4b71Sopenharmony_ci```
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci## wearDetection.isWearDetectionEnabled<sup>11+</sup>
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ciisWearDetectionEnabled(deviceId: string, callback: AsyncCallback&lt;boolean&gt;): void
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci获取设备佩戴检测是否开启。使用Callback异步回调。
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci**参数:**
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
323e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
324e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
325e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;boolean&gt; | 是    | 通过注册回调函数获取设备佩戴检测是否开启。如果成功,值在enabled中返回。 |
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ci**错误码**:
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
332e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
333e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
334e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
335e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
336e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
337e41f4b71Sopenharmony_ci|2900001 | Service stopped.               |
338e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.       |
339e41f4b71Sopenharmony_ci|2900099 | Operation failed.              |
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci**示例:**
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci```js
344e41f4b71Sopenharmony_citry {
345e41f4b71Sopenharmony_ci    wearDetection.isWearDetectionEnabled('XX:XX:XX:XX:XX:XX', (err, enabled) => {
346e41f4b71Sopenharmony_ci        console.info('device enable wear detection ' + enabled);
347e41f4b71Sopenharmony_ci    });
348e41f4b71Sopenharmony_ci} catch (err) {
349e41f4b71Sopenharmony_ci    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
350e41f4b71Sopenharmony_ci}
351e41f4b71Sopenharmony_ci```
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ci## wearDetection.isWearDetectionEnabled<sup>11+</sup>
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ciisWearDetectionEnabled(deviceId: string): Promise&lt;boolean&gt;
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci获取设备佩戴检测是否开启。使用Promise异步回调。
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci**参数:**
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
368e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
369e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci**返回值:**
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci| 类型                            | 说明         |
374e41f4b71Sopenharmony_ci| ----------------------------- | ---------- |
375e41f4b71Sopenharmony_ci| Promise&lt;boolean&gt; | 以Promise的形式获取设备佩戴检测是否开启。如果成功,值在enabled中返回。 |
376e41f4b71Sopenharmony_ci
377e41f4b71Sopenharmony_ci**错误码**:
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
382e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
383e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
384e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
385e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
386e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
387e41f4b71Sopenharmony_ci|2900001 | Service stopped.               |
388e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.       |
389e41f4b71Sopenharmony_ci|2900099 | Operation failed.              |
390e41f4b71Sopenharmony_ci
391e41f4b71Sopenharmony_ci**示例:**
392e41f4b71Sopenharmony_ci
393e41f4b71Sopenharmony_ci```js
394e41f4b71Sopenharmony_citry {
395e41f4b71Sopenharmony_ci    wearDetection.isWearDetectionEnabled('XX:XX:XX:XX:XX:XX').then((enabled) => {
396e41f4b71Sopenharmony_ci        console.info('device enable wear detection ' + enabled);
397e41f4b71Sopenharmony_ci    });
398e41f4b71Sopenharmony_ci} catch (err) {
399e41f4b71Sopenharmony_ci    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
400e41f4b71Sopenharmony_ci}
401e41f4b71Sopenharmony_ci```