openharmony 鸿蒙 js-apis-enterprise-wifiManager

2025-06-12 浏览 (1)

@ohos.enterprise.wifiManager (Wi-Fi Management)

The wifiManager module provides Wi-Fi management capabilities for enterprise devices, including obtaining the Wi-Fi status.

NOTE

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.

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 that is enabled.

The global restriction policies are provided by restrictions. To disable Wi-Fi globally, see @ohos.enterprise.restrictions.

Modules to Import

import { wifiManager } from '@kit.MDMKit';

wifiManager.isWifiActiveSync

isWifiActiveSync(admin: Want): boolean

Queries the Wi-Fi status.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_WIFI

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.

Return value

TypeDescription
booleanReturns the Wi-Fi status. The value true means Wi-Fi is enabled, and the value false means the opposite.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

try {
  let result: boolean = wifiManager.isWifiActiveSync(wantTemp);
  console.info(`Succeeded in query is wifi active or not, result : ${result}`);
} catch (err) {
  console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
}

wifiManager.setWifiProfileSync

setWifiProfileSync(admin: Want, profile: WifiProfile): void

Sets Wi-Fi for the device to connect to the specified network.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_WIFI

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesEnterpriseAdminExtensionAbility.
profileWifiProfileYesWi-Fi profile information.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

IDError Message
9200001The application is not an administrator application of the device.
9200002The administrator application does not have permission to manage the device.
201Permission verification failed. The application does not have the permission required to call the API.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

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
};

try {
  wifiManager.setWifiProfileSync(wantTemp, profile);
  console.info('Succeeded in setting wifi profile.');
} catch (err) {
  console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
}

WifiProfile

Wi-Fi profile information.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameTypeMandatoryDescription
ssidstringYesSSID of the hotspot, in UTF-8 format.
bssidstringNoBasic service set identifier (BSSID) of the hotspot.
preSharedKeystringYesPre-shared key (PSK) of the hotspot.
isHiddenSsidbooleanNoWhether the network is hidden. The value true indicates that the network is hidden; the value false indicates the opposite.
securityTypeWifiSecurityTypeYesSecurity type.
creatorUidnumberNoID of the creator.
disableReasonnumberNoReason for disabling Wi-Fi.
netIdnumberNoNetwork ID allocated.
randomMacTypenumberNoRandom MAC.
randomMacAddrstringNoRandom MAC address.
ipTypeIpTypeNoIP address type.
staticIpIpProfileNoStatic IP address information.
eapProfileWifiEapProfileNoExtensible Authentication Protocol (EAP) configuration.

WifiSecurityType

Enumerates the Wi-Fi security types.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameValueDescription
WIFI_SEC_TYPE_INVALID0Invalid security type.
WIFI_SEC_TYPE_OPEN1Open security type.
WIFI_SEC_TYPE_WEP2Wired Equivalent Privacy (WEP).
WIFI_SEC_TYPE_PSK3PSK.
WIFI_SEC_TYPE_SAE4Simultaneous Authentication of Equals (SAE).
WIFI_SEC_TYPE_EAP5EAP.
WIFI_SEC_TYPE_EAP_SUITE_B6Suite B 192-bit encryption.
WIFI_SEC_TYPE_OWE7Opportunistic Wireless Encryption (OWE).
WIFI_SEC_TYPE_WAPI_CERT8WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).
WIFI_SEC_TYPE_WAPI_PSK9WAPI-PSK.

IpType

Enumerates the IP address types.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameValueDescription
STATIC0Static IP address.
DHCP1IP address allocated by DHCP.
UNKNOWN2Not specified.

IpProfile

Represents IP configuration information.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameTypeMandatoryDescription
ipAddressnumberYesIP address.
gatewaynumberYesGateway.
prefixLengthnumberYesSubnet mask.
dnsServersnumber[]YesDomain name server (DNS) information.
domainsArray<string>YesDomain information.

WifiEapProfile

Represents EAP profile (configuration) information.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameTypeMandatoryDescription
eapMethodEapMethodYesEAP authentication method.
phase2MethodPhase2MethodYesPhase 2 authentication method.
identitystringYesIdentity Information.
anonymousIdentitystringYesAnonymous identity.
passwordstringYesPassword.
caCertAliasesstringYesCA certificate alias.
caPathstringYesCA certificate path.
clientCertAliasesstringYesClient certificate alias.
certEntryUint8ArrayYesCA certificate content.
certPasswordstringYesCA certificate password.
altSubjectMatchstringYesA string to match the alternate subject.
domainSuffixMatchstringYesA string to match the domain suffix.
realmstringYesRealm for the passpoint credential.
plmnstringYesPublic land mobile network (PLMN) of the passpoint credential provider.
eapSubIdnumberYesSub-ID of the SIM card.

EapMethod

Enumerates the EAP authentication methods.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameValueDescription
EAP_NONE0Not specified.
EAP_PEAP1PEAP.
EAP_TLS2TLS.
EAP_TTLS3TTLS.
EAP_PWD4Password.
EAP_SIM5SIM.
EAP_AKA6AKA.
EAP_AKA_PRIME7AKA Prime.
EAP_UNAUTH_TLS8UNAUTH TLS.

Phase2Method

Enumerates the Phase 2 authentication methods.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameValueDescription
PHASE2_NONE0Not specified.
PHASE2_PAP1PAP.
PHASE2_MSCHAP2MS-CHAP.
PHASE2_MSCHAPV23MS-CHAPv2.
PHASE2_GTC4GTC.
PHASE2_SIM5SIM.
PHASE2_AKA6AKA.
PHASE2_AKA_PRIME7AKA Prime.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙MDM Kit

harmony 鸿蒙Enterprise Device Management Error Codes

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony 鸿蒙@ohos.enterprise.accountManager (Account Management) (System API)

harmony 鸿蒙@ohos.enterprise.accountManager (Account Management)

harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management) (System API)

harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management)

harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management (System API)

harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management)

harmony 鸿蒙@ohos.enterprise.bluetoothManager (Bluetooth Management) (System API)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/AO6wk4