1# @ohos.bluetooth.wearDetection (Bluetooth Wear Detection Module) (System API) 2 3The **bluetooth.wearDetection** module provides APIs for checking whether a Bluetooth audio device (such as a Bluetooth earphone) supports wear detection and whether wear detection is enabled, and enabling or disabling wear detection for a device. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> - The APIs provided by this module are system APIs. 9 10 11 12## Modules to Import 13 14```js 15import { wearDetection } from '@kit.ConnectivityKit'; 16``` 17 18 19## wearDetection.enableWearDetection<sup>11+</sup> 20 21enableWearDetection(deviceId: string, callback: AsyncCallback<void>): void 22 23Enables wear detection for a device. This API uses an asynchronous callback to return the result. 24 25**System API**: This is a system API. 26 27**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 28 29**System capability**: SystemCapability.Communication.Bluetooth.Core 30 31**Parameters** 32 33| Name | Type | Mandatory | Description | 34| ------ | ------ | ---- | ------- | 35| deviceId | string | Yes | Address of the remote device.| 36| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 37 38**Error codes** 39 40For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 41 42| ID| Error Message| 43| -------- | ---------------------------- | 44|201 | Permission denied. | 45|202 | Non-system applications are not allowed to use system APIs. | 46|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 47|801 | Capability not supported. | 48|2900001 | Service stopped. | 49|2900003 | Bluetooth disabled. | 50|2900099 | Operation failed. | 51 52**Example** 53 54```js 55try { 56 wearDetection.enableWearDetection('XX:XX:XX:XX:XX:XX', (err) => { 57 if (err) { 58 console.error("enableWearDetection error"); 59 } 60 }); 61} catch (err) { 62 console.error('errCode: ' + err.code + ', errMessage: ' + err.message); 63} 64``` 65 66## wearDetection.enableWearDetection<sup>11+</sup> 67 68enableWearDetection(deviceId: string): Promise<void> 69 70Enables wear detection for a device. This API uses a promise to return the result. 71 72**System API**: This is a system API. 73 74**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 75 76**System capability**: SystemCapability.Communication.Bluetooth.Core 77 78**Parameters** 79 80| Name | Type | Mandatory | Description | 81| ------ | ------ | ---- | ------- | 82| deviceId | string | Yes | Address of the remote device.| 83 84**Return value** 85 86| Type | Description | 87| ----------------------------- | ---------- | 88| Promise<void> | Promise used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 89 90**Error codes** 91 92For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 93 94| ID| Error Message| 95| -------- | ---------------------------- | 96|201 | Permission denied. | 97|202 | Non-system applications are not allowed to use system APIs. | 98|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 99|801 | Capability not supported. | 100|2900001 | Service stopped. | 101|2900003 | Bluetooth disabled. | 102|2900099 | Operation failed. | 103 104**Example** 105 106```js 107try { 108 wearDetection.enableWearDetection('XX:XX:XX:XX:XX:XX').then(() => { 109 console.info("enableWearDetection"); 110 }); 111} catch (err) { 112 console.error('errCode: ' + err.code + ', errMessage: ' + err.message); 113} 114``` 115 116## wearDetection.disableWearDetection<sup>11+</sup> 117 118disableWearDetection(deviceId: string, callback: AsyncCallback<void>): void 119 120Disables wear detection for a device. This API uses an asynchronous callback to return the result. 121 122**System API**: This is a system API. 123 124**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 125 126**System capability**: SystemCapability.Communication.Bluetooth.Core 127 128**Parameters** 129 130| Name | Type | Mandatory | Description | 131| ------ | ------ | ---- | ------- | 132| deviceId | string | Yes | Address of the remote device.| 133| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 134 135**Error codes** 136 137For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 138 139| ID| Error Message| 140| -------- | ---------------------------- | 141|201 | Permission denied. | 142|202 | Non-system applications are not allowed to use system APIs. | 143|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 144|801 | Capability not supported. | 145|2900001 | Service stopped. | 146|2900003 | Bluetooth disabled. | 147|2900099 | Operation failed. | 148 149**Example** 150 151```js 152try { 153 wearDetection.disableWearDetection('XX:XX:XX:XX:XX:XX', (err) => { 154 if (err) { 155 console.error("disableWearDetection error"); 156 } 157 }); 158} catch (err) { 159 console.error('errCode: ' + err.code + ', errMessage: ' + err.message); 160} 161``` 162 163## wearDetection.disableWearDetection<sup>11+</sup> 164 165disableWearDetection(deviceId: string): Promise<void> 166 167Disables wear detection for a device. This API uses a promise to return the result. 168 169**System API**: This is a system API. 170 171**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 172 173**System capability**: SystemCapability.Communication.Bluetooth.Core 174 175**Parameters** 176 177| Name | Type | Mandatory | Description | 178| ------ | ------ | ---- | ------- | 179| deviceId | string | Yes | Address of the remote device.| 180 181**Return value** 182 183| Type | Description | 184| ----------------------------- | ---------- | 185| Promise<void> | Promise used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 186 187**Error codes** 188 189For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 190 191| ID| Error Message| 192| -------- | ---------------------------- | 193|201 | Permission denied. | 194|202 | Non-system applications are not allowed to use system APIs. | 195|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 196|801 | Capability not supported. | 197|2900001 | Service stopped. | 198|2900003 | Bluetooth disabled. | 199|2900099 | Operation failed. | 200 201**Example** 202 203```js 204try { 205 wearDetection.disableWearDetection('XX:XX:XX:XX:XX:XX').then(() => { 206 console.info("disableWearDetection"); 207 }); 208} catch (err) { 209 console.error('errCode: ' + err.code + ', errMessage: ' + err.message); 210} 211``` 212 213## wearDetection.isWearDetectionSupported<sup>11+</sup> 214 215isWearDetectionSupported(deviceId: string, callback: AsyncCallback<boolean>): void 216 217Checks whether a device supports wear detection. This API uses an asynchronous callback to return the result. 218 219**System API**: This is a system API. 220 221**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 222 223**System capability**: SystemCapability.Communication.Bluetooth.Core 224 225**Parameters** 226 227| Name | Type | Mandatory | Description | 228| ------ | ------ | ---- | ------- | 229| deviceId | string | Yes | Address of the remote device.| 230| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the device supports wear detection, **supported** is returned.| 231 232**Error codes** 233 234For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 235 236| ID| Error Message| 237| -------- | ---------------------------- | 238|201 | Permission denied. | 239|202 | Non-system applications are not allowed to use system APIs. | 240|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 241|801 | Capability not supported. | 242|2900001 | Service stopped. | 243|2900003 | Bluetooth disabled. | 244|2900099 | Operation failed. | 245 246**Example** 247 248```js 249try { 250 wearDetection.isWearDetectionSupported('XX:XX:XX:XX:XX:XX', (err, supported) => { 251 console.info('device support wear detection ' + supported); 252 }); 253} catch (err) { 254 console.error('errCode: ' + err.code + ', errMessage: ' + err.message); 255} 256``` 257 258## wearDetection.isWearDetectionSupported<sup>11+</sup> 259 260isWearDetectionSupported(deviceId: string): Promise<boolean> 261 262Checks whether a device supports wear detection. This API uses a promise to return the result. 263 264**System API**: This is a system API. 265 266**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 267 268**System capability**: SystemCapability.Communication.Bluetooth.Core 269 270**Parameters** 271 272| Name | Type | Mandatory | Description | 273| ------ | ------ | ---- | ------- | 274| deviceId | string | Yes | Address of the remote device.| 275 276**Return value** 277 278| Type | Description | 279| ----------------------------- | ---------- | 280| Promise<boolean> | Promise used to return the result. If the device supports wear detection, **supported** is returned.| 281 282**Error codes** 283 284For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 285 286| ID| Error Message| 287| -------- | ---------------------------- | 288|201 | Permission denied. | 289|202 | Non-system applications are not allowed to use system APIs. | 290|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 291|801 | Capability not supported. | 292|2900001 | Service stopped. | 293|2900003 | Bluetooth disabled. | 294|2900099 | Operation failed. | 295 296**Example** 297 298```js 299try { 300 wearDetection.isWearDetectionSupported('XX:XX:XX:XX:XX:XX').then((supported) => { 301 console.info('device support wear detection ' + supported); 302 }); 303} catch (err) { 304 console.error('errCode: ' + err.code + ', errMessage: ' + err.message); 305} 306``` 307 308## wearDetection.isWearDetectionEnabled<sup>11+</sup> 309 310isWearDetectionEnabled(deviceId: string, callback: AsyncCallback<boolean>): void 311 312Checks whether wear detection is enabled for a device. This API uses an asynchronous callback to return the result. 313 314**System API**: This is a system API. 315 316**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 317 318**System capability**: SystemCapability.Communication.Bluetooth.Core 319 320**Parameters** 321 322| Name | Type | Mandatory | Description | 323| ------ | ------ | ---- | ------- | 324| deviceId | string | Yes | Address of the remote device.| 325| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If wear detection is enabled, **enabled** is returned.| 326 327**Error codes** 328 329For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 330 331| ID| Error Message| 332| -------- | ---------------------------- | 333|201 | Permission denied. | 334|202 | Non-system applications are not allowed to use system APIs. | 335|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 336|801 | Capability not supported. | 337|2900001 | Service stopped. | 338|2900003 | Bluetooth disabled. | 339|2900099 | Operation failed. | 340 341**Example** 342 343```js 344try { 345 wearDetection.isWearDetectionEnabled('XX:XX:XX:XX:XX:XX', (err, enabled) => { 346 console.info('device enable wear detection ' + enabled); 347 }); 348} catch (err) { 349 console.error('errCode: ' + err.code + ', errMessage: ' + err.message); 350} 351``` 352 353## wearDetection.isWearDetectionEnabled<sup>11+</sup> 354 355isWearDetectionEnabled(deviceId: string): Promise<boolean> 356 357Checks whether wear detection is enabled for a device. This API uses a promise to return the result. 358 359**System API**: This is a system API. 360 361**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 362 363**System capability**: SystemCapability.Communication.Bluetooth.Core 364 365**Parameters** 366 367| Name | Type | Mandatory | Description | 368| ------ | ------ | ---- | ------- | 369| deviceId | string | Yes | Address of the remote device.| 370 371**Return value** 372 373| Type | Description | 374| ----------------------------- | ---------- | 375| Promise<boolean> | Promise used to return the result. If wear detection is enabled, **enabled** is returned.| 376 377**Error codes** 378 379For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 380 381| ID| Error Message| 382| -------- | ---------------------------- | 383|201 | Permission denied. | 384|202 | Non-system applications are not allowed to use system APIs. | 385|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 386|801 | Capability not supported. | 387|2900001 | Service stopped. | 388|2900003 | Bluetooth disabled. | 389|2900099 | Operation failed. | 390 391**Example** 392 393```js 394try { 395 wearDetection.isWearDetectionEnabled('XX:XX:XX:XX:XX:XX').then((enabled) => { 396 console.info('device enable wear detection ' + enabled); 397 }); 398} catch (err) { 399 console.error('errCode: ' + err.code + ', errMessage: ' + err.message); 400} 401``` 402