1# @ohos.enterprise.wifiManager (Wi-Fi Management) (System API) 2 3The **wifiManager** module provides APIs for Wi-Fi management of enterprise devices. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs of this module can be used only in the stage model. 10> 11> - The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin-2). 12> 13> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.wifiManager](js-apis-enterprise-wifiManager.md). 14 15## Modules to Import 16 17```ts 18import { wifiManager } from '@kit.MDMKit'; 19``` 20 21## wifiManager.isWifiActive 22 23isWifiActive(admin: Want, callback: AsyncCallback<boolean>): void 24 25Queries the Wi-Fi status of the current device. This API uses an asynchronous callback to return the result. 26 27**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI 28 29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30 31 32 33**Parameters** 34 35| Name | Type | Mandatory | Description | 36| -------- | ---------------------------------------- | ---- | ------------------------------- | 37| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 38| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a Boolean value (**true** indicates that Wi-Fi is active; and **false** indicates that Wi-Fi is inactive). If the operation fails, **err** is an error object. | 39 40**Error codes** 41 42For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 43 44| ID| Error Message | 45| ------- | ---------------------------------------------------------------------------- | 46| 9200001 | The application is not an administrator application of the device. | 47| 9200002 | The administrator application does not have permission to manage the device. | 48| 201 | Permission verification failed. The application does not have the permission required to call the API. | 49| 202 | Permission verification failed. A non-system application calls a system API. | 50| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 51 52**Example** 53 54```ts 55import { Want } from '@kit.AbilityKit'; 56 57let wantTemp: Want = { 58 bundleName: 'com.example.myapplication', 59 abilityName: 'EntryAbility', 60}; 61 62wifiManager.isWifiActive(wantTemp, (err, result) => { 63 if (err) { 64 console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`); 65 return; 66 } 67 console.info(`Succeeded in query is wifi active or not, result : ${result}`); 68}); 69``` 70 71## wifiManager.isWifiActive 72 73isWifiActive(admin: Want): Promise<boolean> 74 75Queries the Wi-Fi status of the current device. This API uses a promise to return the result. 76 77**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI 78 79**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 80 81 82 83**Parameters** 84 85| Name | Type | Mandatory | Description | 86| ----- | ----------------------------------- | ---- | ------- | 87| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 88 89**Return value** 90 91| Type | Description | 92| --------------------- | ------------------------- | 93| Promise<boolean> | Promise used to return the Wi-Fi status.<br>The value **true** means that Wi-Fi is enabled; the value **false** means the opposite. | 94 95**Error codes** 96 97For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 98 99| ID| Error Message | 100| ------- | ---------------------------------------------------------------------------- | 101| 9200001 | The application is not an administrator application of the device. | 102| 9200002 | The administrator application does not have permission to manage the device. | 103| 201 | Permission verification failed. The application does not have the permission required to call the API. | 104| 202 | Permission verification failed. A non-system application calls a system API. | 105| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 106 107**Example** 108 109```ts 110import { Want } from '@kit.AbilityKit'; 111import { BusinessError } from '@kit.BasicServicesKit'; 112 113let wantTemp: Want = { 114 bundleName: 'com.example.myapplication', 115 abilityName: 'EntryAbility', 116}; 117 118wifiManager.isWifiActive(wantTemp).then((result) => { 119 console.info(`Succeeded in query is wifi active or not, result : ${result}`); 120}).catch((err: BusinessError) => { 121 console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`); 122}); 123``` 124 125## wifiManager.setWifiProfile 126 127setWifiProfile(admin: Want, profile: WifiProfile, callback: AsyncCallback<void>): void 128 129Configures Wi-Fi for the current device to connect to a specified network. This API uses an asynchronous callback to return the result. 130 131**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI 132 133**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 134 135 136 137**Parameters** 138 139| Name | Type | Mandatory | Description | 140| -------- | ---------------------------------------- | ---- | ------------------------------- | 141| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 142| profile | [WifiProfile](js-apis-enterprise-wifiManager.md#wifiprofile) | Yes | Wi-Fi configuration information. | 143| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 144 145**Error codes** 146 147For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 148 149| ID| Error Message | 150| ------- | ---------------------------------------------------------------------------- | 151| 9200001 | The application is not an administrator application of the device. | 152| 9200002 | The administrator application does not have permission to manage the device. | 153| 201 | Permission verification failed. The application does not have the permission required to call the API. | 154| 202 | Permission verification failed. A non-system application calls a system API. | 155| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 156 157**Example** 158 159```ts 160import { Want } from '@kit.AbilityKit'; 161 162let wantTemp: Want = { 163 bundleName: 'com.example.myapplication', 164 abilityName: 'EntryAbility', 165}; 166let profile: wifiManager.WifiProfile = { 167 'ssid': 'name', 168 'preSharedKey': 'passwd', 169 'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK 170}; 171 172wifiManager.setWifiProfile(wantTemp, profile, (err) => { 173 if (err) { 174 console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`); 175 return; 176 } 177 console.info('Succeeded in setting wifi profile'); 178}); 179``` 180 181## wifiManager.setWifiProfile 182 183setWifiProfile(admin: Want, profile: WifiProfile): Promise<void> 184 185Configures Wi-Fi for the current device to connect to a specified network. This API uses a promise to return the result. 186 187**Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI 188 189**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 190 191 192 193**Parameters** 194 195| Name | Type | Mandatory | Description | 196| ----- | ----------------------------------- | ---- | ------- | 197| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 198| profile | [WifiProfile](js-apis-enterprise-wifiManager.md#wifiprofile) | Yes | Wi-Fi configuration information. | 199 200**Return value** 201 202| Type | Description | 203| --------------------- | ------------------------- | 204| Promise<void> | Promise that returns no value. An error object is thrown if the Wi-Fi fails to be configured.| 205 206**Error codes** 207 208For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 209 210| ID| Error Message | 211| ------- | ---------------------------------------------------------------------------- | 212| 9200001 | The application is not an administrator application of the device. | 213| 9200002 | The administrator application does not have permission to manage the device. | 214| 201 | Permission verification failed. The application does not have the permission required to call the API. | 215| 202 | Permission verification failed. A non-system application calls a system API. | 216| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 217 218**Example** 219 220```ts 221import { Want } from '@kit.AbilityKit'; 222import { BusinessError } from '@kit.BasicServicesKit'; 223 224let wantTemp: Want = { 225 bundleName: 'com.example.myapplication', 226 abilityName: 'EntryAbility', 227}; 228let profile: wifiManager.WifiProfile = { 229 'ssid': 'name', 230 'preSharedKey': 'passwd', 231 'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK 232}; 233 234wifiManager.setWifiProfile(wantTemp, profile).then(() => { 235 console.info('Succeeded in setting wifi profile'); 236}).catch((err: BusinessError) => { 237 console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`); 238}); 239``` 240 241## wifiManager.isWifiDisabled<sup>11+</sup> 242 243isWifiDisabled(admin: Want): boolean 244 245Queries whether Wi-Fi is disabled on the current device. 246 247**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI 248 249**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 250 251**System API**: This is a system API. 252 253**Parameters** 254 255| Name | Type | Mandatory | Description | 256| ----- | ----------------------------------- | ---- | ------- | 257| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 258 259**Return value** 260 261| Type | Description | 262| --------------------- | ------------------------- | 263| boolean | Returns **true** if Wi-Fi is disabled; returns **false** otherwise.| 264 265**Error codes** 266 267For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 268 269| ID| Error Message | 270| ------- | ---------------------------------------------------------------------------- | 271| 9200001 | The application is not an administrator application of the device. | 272| 9200002 | The administrator application does not have permission to manage the device. | 273| 201 | Permission verification failed. The application does not have the permission required to call the API. | 274| 202 | Permission verification failed. A non-system application calls a system API. | 275| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 276 277**Example** 278 279```ts 280import { Want } from '@kit.AbilityKit'; 281 282let wantTemp: Want = { 283 bundleName: 'com.example.myapplication', 284 abilityName: 'EntryAbility', 285}; 286try { 287 let result: boolean = wifiManager.isWifiDisabled(wantTemp); 288 console.info(`Succeeded in query the wifi is disabled or not, result : ${result}`); 289} catch (err) { 290 console.error(`Failed to query the wifi is disabled or not. Code: ${err.code}, message: ${err.message}`); 291}; 292``` 293 294## wifiManager.setWifiDisabled<sup>11+</sup> 295 296setWifiDisabled(admin: Want, disabled: boolean): void 297 298Sets the Wi-Fi disabling policy. 299 300**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI 301 302**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 303 304**System API**: This is a system API. 305 306**Parameters** 307 308| Name | Type | Mandatory| Description | 309| ---------- | ----------------------------------- | ---- | ----------------------------------------- | 310| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 311| disabled | boolean | Yes | Wi-Fi policy to set. The value **true** means to disable Wi-Fi; the value **false** means the opposite.| 312 313**Error codes** 314 315For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 316 317| ID| Error Message | 318| -------- | ------------------------------------------------------------ | 319| 9200001 | The application is not an administrator application of the device. | 320| 9200002 | The administrator application does not have permission to manage the device. | 321| 201 | Permission verification failed. The application does not have the permission required to call the API. | 322| 202 | Permission verification failed. A non-system application calls a system API. | 323| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 324 325**Example** 326 327```ts 328import { Want } from '@kit.AbilityKit'; 329 330let wantTemp: Want = { 331 bundleName: 'com.example.myapplication', 332 abilityName: 'EntryAbility', 333}; 334 335try { 336 wifiManager.setWifiDisabled(wantTemp, true); 337 console.info('Succeeded in set the wifi disabled'); 338} catch (err) { 339 console.error(`Failed to set the wifi disabled. Code: ${err.code}, message: ${err.message}`); 340}; 341``` 342