# @ohos.bluetooth.wearDetection (Bluetooth Wear Detection Module) (System API) The **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. > **NOTE** > > - 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. > - The APIs provided by this module are system APIs. ## Modules to Import ```js import { wearDetection } from '@kit.ConnectivityKit'; ``` ## wearDetection.enableWearDetection11+ enableWearDetection(deviceId: string, callback: AsyncCallback<void>): void Enables wear detection for a device. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | ------- | | deviceId | string | Yes | Address of the remote device.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). | ID| Error Message| | -------- | ---------------------------- | |201 | Permission denied. | |202 | Non-system applications are not allowed to use system APIs. | |401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | |801 | Capability not supported. | |2900001 | Service stopped. | |2900003 | Bluetooth disabled. | |2900099 | Operation failed. | **Example** ```js try { wearDetection.enableWearDetection('XX:XX:XX:XX:XX:XX', (err) => { if (err) { console.error("enableWearDetection error"); } }); } catch (err) { console.error('errCode: ' + err.code + ', errMessage: ' + err.message); } ``` ## wearDetection.enableWearDetection11+ enableWearDetection(deviceId: string): Promise<void> Enables wear detection for a device. This API uses a promise to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | ------- | | deviceId | string | Yes | Address of the remote device.| **Return value** | Type | Description | | ----------------------------- | ---------- | | Promise<void> | Promise used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). | ID| Error Message| | -------- | ---------------------------- | |201 | Permission denied. | |202 | Non-system applications are not allowed to use system APIs. | |401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | |801 | Capability not supported. | |2900001 | Service stopped. | |2900003 | Bluetooth disabled. | |2900099 | Operation failed. | **Example** ```js try { wearDetection.enableWearDetection('XX:XX:XX:XX:XX:XX').then(() => { console.info("enableWearDetection"); }); } catch (err) { console.error('errCode: ' + err.code + ', errMessage: ' + err.message); } ``` ## wearDetection.disableWearDetection11+ disableWearDetection(deviceId: string, callback: AsyncCallback<void>): void Disables wear detection for a device. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | ------- | | deviceId | string | Yes | Address of the remote device.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). | ID| Error Message| | -------- | ---------------------------- | |201 | Permission denied. | |202 | Non-system applications are not allowed to use system APIs. | |401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | |801 | Capability not supported. | |2900001 | Service stopped. | |2900003 | Bluetooth disabled. | |2900099 | Operation failed. | **Example** ```js try { wearDetection.disableWearDetection('XX:XX:XX:XX:XX:XX', (err) => { if (err) { console.error("disableWearDetection error"); } }); } catch (err) { console.error('errCode: ' + err.code + ', errMessage: ' + err.message); } ``` ## wearDetection.disableWearDetection11+ disableWearDetection(deviceId: string): Promise<void> Disables wear detection for a device. This API uses a promise to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | ------- | | deviceId | string | Yes | Address of the remote device.| **Return value** | Type | Description | | ----------------------------- | ---------- | | Promise<void> | Promise used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). | ID| Error Message| | -------- | ---------------------------- | |201 | Permission denied. | |202 | Non-system applications are not allowed to use system APIs. | |401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | |801 | Capability not supported. | |2900001 | Service stopped. | |2900003 | Bluetooth disabled. | |2900099 | Operation failed. | **Example** ```js try { wearDetection.disableWearDetection('XX:XX:XX:XX:XX:XX').then(() => { console.info("disableWearDetection"); }); } catch (err) { console.error('errCode: ' + err.code + ', errMessage: ' + err.message); } ``` ## wearDetection.isWearDetectionSupported11+ isWearDetectionSupported(deviceId: string, callback: AsyncCallback<boolean>): void Checks whether a device supports wear detection. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | ------- | | deviceId | string | Yes | Address of the remote device.| | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the device supports wear detection, **supported** is returned.| **Error codes** For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). | ID| Error Message| | -------- | ---------------------------- | |201 | Permission denied. | |202 | Non-system applications are not allowed to use system APIs. | |401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | |801 | Capability not supported. | |2900001 | Service stopped. | |2900003 | Bluetooth disabled. | |2900099 | Operation failed. | **Example** ```js try { wearDetection.isWearDetectionSupported('XX:XX:XX:XX:XX:XX', (err, supported) => { console.info('device support wear detection ' + supported); }); } catch (err) { console.error('errCode: ' + err.code + ', errMessage: ' + err.message); } ``` ## wearDetection.isWearDetectionSupported11+ isWearDetectionSupported(deviceId: string): Promise<boolean> Checks whether a device supports wear detection. This API uses a promise to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | ------- | | deviceId | string | Yes | Address of the remote device.| **Return value** | Type | Description | | ----------------------------- | ---------- | | Promise<boolean> | Promise used to return the result. If the device supports wear detection, **supported** is returned.| **Error codes** For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). | ID| Error Message| | -------- | ---------------------------- | |201 | Permission denied. | |202 | Non-system applications are not allowed to use system APIs. | |401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | |801 | Capability not supported. | |2900001 | Service stopped. | |2900003 | Bluetooth disabled. | |2900099 | Operation failed. | **Example** ```js try { wearDetection.isWearDetectionSupported('XX:XX:XX:XX:XX:XX').then((supported) => { console.info('device support wear detection ' + supported); }); } catch (err) { console.error('errCode: ' + err.code + ', errMessage: ' + err.message); } ``` ## wearDetection.isWearDetectionEnabled11+ isWearDetectionEnabled(deviceId: string, callback: AsyncCallback<boolean>): void Checks whether wear detection is enabled for a device. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | ------- | | deviceId | string | Yes | Address of the remote device.| | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If wear detection is enabled, **enabled** is returned.| **Error codes** For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). | ID| Error Message| | -------- | ---------------------------- | |201 | Permission denied. | |202 | Non-system applications are not allowed to use system APIs. | |401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | |801 | Capability not supported. | |2900001 | Service stopped. | |2900003 | Bluetooth disabled. | |2900099 | Operation failed. | **Example** ```js try { wearDetection.isWearDetectionEnabled('XX:XX:XX:XX:XX:XX', (err, enabled) => { console.info('device enable wear detection ' + enabled); }); } catch (err) { console.error('errCode: ' + err.code + ', errMessage: ' + err.message); } ``` ## wearDetection.isWearDetectionEnabled11+ isWearDetectionEnabled(deviceId: string): Promise<boolean> Checks whether wear detection is enabled for a device. This API uses a promise to return the result. **System API**: This is a system API. **Required permissions**: ohos.permission.ACCESS_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | ------- | | deviceId | string | Yes | Address of the remote device.| **Return value** | Type | Description | | ----------------------------- | ---------- | | Promise<boolean> | Promise used to return the result. If wear detection is enabled, **enabled** is returned.| **Error codes** For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). | ID| Error Message| | -------- | ---------------------------- | |201 | Permission denied. | |202 | Non-system applications are not allowed to use system APIs. | |401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | |801 | Capability not supported. | |2900001 | Service stopped. | |2900003 | Bluetooth disabled. | |2900099 | Operation failed. | **Example** ```js try { wearDetection.isWearDetectionEnabled('XX:XX:XX:XX:XX:XX').then((enabled) => { console.info('device enable wear detection ' + enabled); }); } catch (err) { console.error('errCode: ' + err.code + ', errMessage: ' + err.message); } ```