harmony 鸿蒙@ohos.enterprise.wifiManager(WiFi管理)
@ohos.enterprise.wifiManager(WiFi管理)
本模块提供企业设备WiFi管理能力,包括查询WiFi开启状态等。
说明:
本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口仅可在Stage模型下使用。
导入模块
import wifiManager from '@ohos.enterprise.wifiManager';
wifiManager.isWifiActive
isWifiActive(admin: Want, callback: AsyncCallback<boolean>): void
指定设备管理应用查询wifi开启状态。使用callback异步回调。
需要权限: ohos.permission.ENTERPRISE_SET_WIFI
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 设备管理应用。 |
| callback | AsyncCallback<boolean> | 是 | 回调函数,当接口调用成功,err为null,data为boolean值,true表示wifi开启,false表示wifi关闭,否则err为错误对象。 |
错误码:
以下的错误码的详细介绍请参见企业设备管理错误码
|错误码ID|错误信息 |
|——-|—————————————————————————-|
|9200001|the application is not an administrator of the device. |
|9200002|the administrator application does not have permission to manage the device.|
示例:
import Want from '@ohos.app.ability.Want';
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>
指定设备管理应用获取wifi开启状态。使用Promise异步回调。
需要权限: ohos.permission.ENTERPRISE_SET_WIFI
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 设备管理应用。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<boolean> | Promise结果,返回wifi开启状态,true表示wifi开启,false表示wifi关闭。 |
错误码:
以下的错误码的详细介绍请参见企业设备管理错误码
|错误码ID|错误信息 |
|——-|—————————————————————————-|
|9200001|the application is not an administrator of the device. |
|9200002|the administrator application does not have permission to manage the device.|
示例:
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
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
指定设备管理应用为设备配置wifi,使连接到指定网络。使用callback异步回调。
需要权限: ohos.permission.ENTERPRISE_SET_WIFI
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 设备管理应用。 |
| profile | WifiProfile | 是 | WLAN配置信息。 |
| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 |
错误码:
以下的错误码的详细介绍请参见企业设备管理错误码
|错误码ID|错误信息 |
|——-|—————————————————————————-|
|9200001|the application is not an administrator of the device. |
|9200002|the administrator application does not have permission to manage the device.|
示例:
import Want from '@ohos.app.ability.Want';
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>
指定设备管理应用为设备配置wifi,使连接到指定网络。使用Promise异步回调。
需要权限: ohos.permission.ENTERPRISE_SET_WIFI
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 设备管理应用。 |
| profile | WifiProfile | 是 | WLAN配置信息。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 无返回结果的Promise对象。当配置wifi连接到指定网络失败时会抛出错误对象。 |
错误码:
以下的错误码的详细介绍请参见企业设备管理错误码
|错误码ID|错误信息 |
|——-|—————————————————————————-|
|9200001|the application is not an administrator of the device. |
|9200002|the administrator application does not have permission to manage the device.|
示例:
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
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}`);
});
WifiProfile
WLAN配置信息
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
| 名称 | 类型 | 可读 | 可写 | 说明 |
|---|---|---|---|---|
| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
| bssid | string | 是 | 否 | 热点的BSSID。 |
| preSharedKey | string | 是 | 否 | 热点的密钥。 |
| isHiddenSsid | boolean | 是 | 否 | 是否是隐藏网络。 |
| securityType | WifiSecurityType | 是 | 否 | 加密类型。 |
| creatorUid | number | 是 | 否 | 创建用户的ID。 |
| disableReason | number | 是 | 否 | 禁用原因。 |
| netId | number | 是 | 否 | 分配的网络ID。 |
| randomMacType | number | 是 | 否 | 随机MAC类型 |
| randomMacAddr | string | 是 | 否 | 随机MAC地址 |
| ipType | IpType | 是 | 否 | IP地址类型 |
| staticIp | IpProfile | 是 | 否 | 静态IP配置信息。 |
| eapProfile | WifiEapProfile | 是 | 否 | 可扩展身份验证协议配置。 |
WifiSecurityType
表示加密类型的枚举。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
| 名称 | 值 | 说明 |
|---|---|---|
| WIFI_SEC_TYPE_INVALID | 0 | 无效加密类型。 |
| WIFI_SEC_TYPE_OPEN | 1 | 开放加密类型。 |
| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP)加密类型。 |
| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (PSK)加密类型。 |
| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE)加密类型。 |
| WIFI_SEC_TYPE_EAP | 5 | EAP加密类型。 |
| WIFI_SEC_TYPE_EAP_SUITE_B | 6 | Suite-B 192位加密类型。 |
| WIFI_SEC_TYPE_OWE | 7 | 机会性无线加密类型。 |
| WIFI_SEC_TYPE_WAPI_CERT | 8 | WAPI-Cert加密类型。 |
| WIFI_SEC_TYPE_WAPI_PSK | 9 | WAPI-PSK加密类型。 |
IpType
表示IP类型的枚举。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
| 名称 | 值 | 说明 |
|---|---|---|
| STATIC | 0 | 静态IP。 |
| DHCP | 1 | 通过DHCP获取。 |
| UNKNOWN | 2 | 未指定。 |
IpProfile
IP配置信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
| 名称 | 类型 | 可读 | 可写 | 说明 |
|---|---|---|---|---|
| ipAddress | number | 是 | 否 | IP地址。 |
| gateway | number | 是 | 否 | 网关。 |
| prefixLength | number | 是 | 否 | 掩码。 |
| dnsServers | number[] | 是 | 否 | DNS服务器。 |
| domains | Array<string> | 是 | 否 | 域信息。 |
WifiEapProfile
可扩展身份验证协议配置信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
| 名称 | 类型 | 可读 | 可写 | 说明 |
|---|---|---|---|---|
| eapMethod | EapMethod | 是 | 否 | EAP认证方式。 |
| phase2Method | Phase2Method | 是 | 否 | 第二阶段认证方式。 |
| identity | string | 是 | 否 | 身份信息。 |
| anonymousIdentity | string | 是 | 否 | 匿名身份。 |
| password | string | 是 | 否 | 密码。 |
| caCertAliases | string | 是 | 否 | CA 证书别名。 |
| caPath | string | 是 | 否 | CA 证书路径。 |
| clientCertAliases | string | 是 | 否 | 客户端证书别名。 |
| certEntry | Uint8Array | 是 | 是 | CA 证书内容。 |
| certPassword | string | 是 | 是 | CA证书密码。 |
| altSubjectMatch | string | 是 | 否 | 替代主题匹配。 |
| domainSuffixMatch | string | 是 | 否 | 域后缀匹配。 |
| realm | string | 是 | 否 | 通行证凭证的领域。 |
| plmn | string | 是 | 否 | 公共陆地移动网的直通凭证提供商。 |
| eapSubId | number | 是 | 否 | SIM卡的子ID。 |
EapMethod
表示EAP认证方式的枚举。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
| 名称 | 值 | 说明 |
|---|---|---|
| EAP_NONE | 0 | 不指定。 |
| EAP_PEAP | 1 | PEAP类型。 |
| EAP_TLS | 2 | TLS类型。 |
| EAP_TTLS | 3 | TTLS类型。 |
| EAP_PWD | 4 | PWD类型。 |
| EAP_SIM | 5 | SIM类型。 |
| EAP_AKA | 6 | AKA类型。 |
| EAP_AKA_PRIME | 7 | AKA Prime类型。 |
| EAP_UNAUTH_TLS | 8 | UNAUTH TLS类型。 |
Phase2Method
表示第二阶段认证方式的枚举。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
系统API: 此接口为系统接口。
| 名称 | 值 | 说明 |
|---|---|---|
| PHASE2_NONE | 0 | 不指定。 |
| PHASE2_PAP | 1 | PAP类型。 |
| PHASE2_MSCHAP | 2 | MSCHAP类型。 |
| PHASE2_MSCHAPV2 | 3 | MSCHAPV2类型。 |
| PHASE2_GTC | 4 | GTC类型。 |
| PHASE2_SIM | 5 | SIM类型。 |
| PHASE2_AKA | 6 | AKA类型。 |
| PHASE2_AKA_PRIME | 7 | AKA Prime类型。 |
你可能感兴趣的鸿蒙文章
harmony 鸿蒙BundleStatusCallback
harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)
harmony 鸿蒙@ohos.distributedBundle (分布式包管理)
harmony 鸿蒙@ohos.bundle (Bundle模块)
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 openharmony
-
9、 golang