1e41f4b71Sopenharmony_ci# @ohos.enterprise.bluetoothManager (Bluetooth Management) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **bluetoothManager** module provides Bluetooth management capabilities, including setting and obtaining Bluetooth information. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> The APIs of this module can be used only in the stage model. 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Modules to Import 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport { bluetoothManager } from '@kit.MDMKit'; 17e41f4b71Sopenharmony_ci``` 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## bluetoothManager.getBluetoothInfo 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_cigetBluetoothInfo(admin: Want): BluetoothInfo 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciObtains device Bluetooth information through the specified device administrator application. This API returns the result synchronously. If the operation is successful, the Bluetooth information obtained is returned. If the operation fails, an exception will be thrown. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**Parameters** 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 34e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | -------------- | 35e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Return value** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci| Type | Description | 40e41f4b71Sopenharmony_ci| ------------------------------- | ------------------------------------------------ | 41e41f4b71Sopenharmony_ci| [BluetoothInfo](#bluetoothinfo) | Bluetooth information, including the Bluetooth name, state, and profile connection state.| 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**Error codes** 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci| ID| Error Message | 48e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 49e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 50e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 51e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 52e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**Example** 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci```ts 57e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 58e41f4b71Sopenharmony_ciimport { bluetoothManager } from '@kit.MDMKit'; 59e41f4b71Sopenharmony_cilet wantTemp: Want = { 60e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 61e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 62e41f4b71Sopenharmony_ci}; 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_citry { 65e41f4b71Sopenharmony_ci let result: bluetoothManager.BluetoothInfo = bluetoothManager.getBluetoothInfo(wantTemp); 66e41f4b71Sopenharmony_ci console.info(`Succeeded in getting bluetooth info: ${JSON.stringify(result)}`); 67e41f4b71Sopenharmony_ci} catch(err) { 68e41f4b71Sopenharmony_ci console.error(`Failed to get bluetooth info. Code: ${err.code}, message: ${err.message}`); 69e41f4b71Sopenharmony_ci} 70e41f4b71Sopenharmony_ci``` 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci## bluetoothManager.addAllowedBluetoothDevices 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciaddAllowedBluetoothDevices(admin: Want, deviceIds: Array\<string>): void 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ciAdds allowed Bluetooth devices through the specified device administrator application. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**Parameters** 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 87e41f4b71Sopenharmony_ci| --------- | ------------------------------------------------------- | ---- | --------------------------------------------------- | 88e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 89e41f4b71Sopenharmony_ci| deviceIds | Array\<string> | Yes | MAC addresses of the Bluetooth devices to add. This array can hold a maximum of 1000 MAC addresses.| 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**Error codes** 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci| ID| Error Message | 96e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 97e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 98e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 99e41f4b71Sopenharmony_ci| 9200010 | A conflict policy has been configured. | 100e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 101e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**Example** 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci```ts 106e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 107e41f4b71Sopenharmony_ciimport { bluetoothManager } from '@kit.MDMKit'; 108e41f4b71Sopenharmony_cilet wantTemp: Want = { 109e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 110e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 111e41f4b71Sopenharmony_ci}; 112e41f4b71Sopenharmony_cilet deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"]; 113e41f4b71Sopenharmony_citry { 114e41f4b71Sopenharmony_ci bluetoothManager.addAllowedBluetoothDevices(wantTemp,deviceIds); 115e41f4b71Sopenharmony_ci console.info(`Succeeded in adding allowed bluetooth devices.`); 116e41f4b71Sopenharmony_ci} catch(err) { 117e41f4b71Sopenharmony_ci console.error(`Failed to add allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 118e41f4b71Sopenharmony_ci} 119e41f4b71Sopenharmony_ci``` 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci## bluetoothManager.removeAllowedBluetoothDevices 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciremoveAllowedBluetoothDevices(admin: Want, deviceIds: Array\<string>): void 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ciRemoves allowed Bluetooth devices through the specified device administrator application. 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**Parameters** 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 136e41f4b71Sopenharmony_ci| --------- | ------------------------------------------------------- | ---- | ----------------------- | 137e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 138e41f4b71Sopenharmony_ci| deviceIds | Array\<string> | Yes | MAC addresses of the Bluetooth devices to remove.| 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**Error codes** 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci| ID| Error Message | 145e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 146e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 147e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 148e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 149e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**Example** 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci```ts 154e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 155e41f4b71Sopenharmony_ciimport { bluetoothManager } from '@kit.MDMKit'; 156e41f4b71Sopenharmony_cilet wantTemp: Want = { 157e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 158e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 159e41f4b71Sopenharmony_ci}; 160e41f4b71Sopenharmony_cilet deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"]; 161e41f4b71Sopenharmony_citry { 162e41f4b71Sopenharmony_ci bluetoothManager.removeAllowedBluetoothDevices(wantTemp,deviceIds); 163e41f4b71Sopenharmony_ci console.info(`Succeeded in removing allowed bluetooth devices.`); 164e41f4b71Sopenharmony_ci} catch(err) { 165e41f4b71Sopenharmony_ci console.error(`Failed to remove allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 166e41f4b71Sopenharmony_ci} 167e41f4b71Sopenharmony_ci``` 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci## bluetoothManager.getAllowedBluetoothDevices 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_cigetAllowedBluetoothDevices(admin: Want): Array\<string>; 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ciObtains allowed Bluetooth devices through the specified device administrator application. 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci**Parameters** 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 184e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | -------------- | 185e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**Return value** 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci| Type | Description | 190e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | 191e41f4b71Sopenharmony_ci| Array\<string> | MAC addresses of allowed Bluetooth devices obtained.| 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**Error codes** 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci| ID| Error Message | 198e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 199e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 200e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. | 201e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 202e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci**Example** 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci```ts 207e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 208e41f4b71Sopenharmony_ciimport { bluetoothManager } from '@kit.MDMKit'; 209e41f4b71Sopenharmony_cilet wantTemp: Want = { 210e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 211e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 212e41f4b71Sopenharmony_ci}; 213e41f4b71Sopenharmony_citry { 214e41f4b71Sopenharmony_ci let result: Array<string> = bluetoothManager.getAllowedBluetoothDevices(wantTemp); 215e41f4b71Sopenharmony_ci console.info(`Succeeded in getting allowed bluetooth devices. Result: ${JSON.stringify(result)}`); 216e41f4b71Sopenharmony_ci} catch(err) { 217e41f4b71Sopenharmony_ci console.error(`Failed to get allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 218e41f4b71Sopenharmony_ci} 219e41f4b71Sopenharmony_ci``` 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci## BluetoothInfo 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ciRepresents the device Bluetooth information. 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 232e41f4b71Sopenharmony_ci| --------------- | ------------------------------------------------------------ | ---- | ------------------------ | 233e41f4b71Sopenharmony_ci| name | string | Yes | Bluetooth name of the device. | 234e41f4b71Sopenharmony_ci| state | [access.BluetoothState](../apis-connectivity-kit/js-apis-bluetooth-access.md#bluetoothstate) | Yes | Bluetooth state of the device. | 235e41f4b71Sopenharmony_ci| connectionState | [constant.ProfileConnectionState](../apis-connectivity-kit/js-apis-bluetooth-constant.md#profileconnectionstate) | Yes | Bluetooth profile connection state of the device.| 236