# @ohos.enterprise.wifiManager (Wi-Fi Management) (System API) The **wifiManager** module provides APIs for Wi-Fi management of enterprise devices. > **NOTE** > > 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. > > The APIs of this module can be used only in the stage model. > > 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). > > 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). ## Modules to Import ```ts import { wifiManager } from '@kit.MDMKit'; ``` ## wifiManager.isWifiActive isWifiActive(admin: Want, callback: AsyncCallback<boolean>): void Checks whether Wi-Fi is active through the specified device administrator application. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------------------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | | callback | AsyncCallback<boolean> | Yes | Callback used 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. | **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; wifiManager.isWifiActive(wantTemp, (err, result) => { if (err) { console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`); return; } console.info(`Succeeded in query is wifi active or not, result : ${result}`); }); ``` ## wifiManager.isWifiActive isWifiActive(admin: Want): Promise<boolean> Checks whether Wi-Fi is active through the specified device administrator application. This API uses a promise to return the result. **Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ----------------------------------- | ---- | ------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<boolean> | Promise used to return the result. The value **true** indicates that Wi-Fi is active, and the value **false** indicates that Wi-Fi is inactive. | **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; wifiManager.isWifiActive(wantTemp).then((result) => { console.info(`Succeeded in query is wifi active or not, result : ${result}`); }).catch((err: BusinessError) => { console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`); }); ``` ## wifiManager.setWifiProfile setWifiProfile(admin: Want, profile: WifiProfile, callback: AsyncCallback<void>): void Sets Wi-Fi profile through the specified device administrator application to enable the device to connect to the specified network. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------------------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | | profile | [WifiProfile](js-apis-enterprise-wifiManager.md#wifiprofile) | Yes | Wi-Fi profile information. | | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; let profile: wifiManager.WifiProfile = { 'ssid': 'name', 'preSharedKey': 'passwd', 'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK }; wifiManager.setWifiProfile(wantTemp, profile, (err) => { if (err) { console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in setting wifi profile'); }); ``` ## wifiManager.setWifiProfile setWifiProfile(admin: Want, profile: WifiProfile): Promise<void> Sets Wi-Fi profile through the specified device administrator application to enable the device to connect to the specified network. This API uses a promise to return the result. **Required permissions**: ohos.permission.ENTERPRISE_SET_WIFI **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ----------------------------------- | ---- | ------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| | profile | [WifiProfile](js-apis-enterprise-wifiManager.md#wifiprofile) | Yes | Wi-Fi profile information. | **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; let profile: wifiManager.WifiProfile = { 'ssid': 'name', 'preSharedKey': 'passwd', 'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK }; wifiManager.setWifiProfile(wantTemp, profile).then(() => { console.info('Succeeded in setting wifi profile'); }).catch((err: BusinessError) => { console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`); }); ``` ## wifiManager.isWifiDisabled11+ isWifiDisabled(admin: Want): boolean Checks whether Wi-Fi is disabled through the specified device administrator application. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. **Parameters** | Name | Type | Mandatory | Description | | ----- | ----------------------------------- | ---- | ------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| **Return value** | Type | Description | | --------------------- | ------------------------- | | boolean | Returns **true** if Wi-Fi is disabled; returns **false** otherwise.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | ------- | ---------------------------------------------------------------------------- | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; try { let result: boolean = wifiManager.isWifiDisabled(wantTemp); console.info(`Succeeded in query the wifi is disabled or not, result : ${result}`); } catch (err) { console.error(`Failed to query the wifi is disabled or not. Code: ${err.code}, message: ${err.message}`); }; ``` ## wifiManager.setWifiDisabled11+ setWifiDisabled(admin: Want, disabled: boolean): void Sets the Wi-Fi policy through the specified device administrator application. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **System API**: This is a system API. **Parameters** | Name | Type | Mandatory| Description | | ---------- | ----------------------------------- | ---- | ----------------------------------------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | | disabled | boolean | Yes | Whether to disable Wi-Fi. The value **true** means to disable Wi-Fi; the value **false** means the opposite.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; try { wifiManager.setWifiDisabled(wantTemp, true); console.info('Succeeded in set the wifi disabled'); } catch (err) { console.error(`Failed to set the wifi disabled. Code: ${err.code}, message: ${err.message}`); }; ```