gpt4 book ai didi

android - 如何从 Android WifiConfiguration 条目获取 WiFi 安全性(NONE、WEP、WPA、WPA2)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:50:13 25 4
gpt4 key购买 nike

我需要从 WifiConfiguration 条目中获取安全类型。可能吗?

String getSecurityType(WifiConfiguration conf) {
}

返回值 “NONE”、“WEP”、“WPA”、“WPA2”

对于那些认为这是重复问题的人:我想从 WiFiConfiguration 对象而不是 ScanResult 对象获取信息。这不一样!

最佳答案

我可以做到,很简单:

import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt;

public static final int SECURITY_NONE = 0;
public static final int SECURITY_WEP = 1;
public static final int SECURITY_PSK = 2;
public static final int SECURITY_EAP = 3;

public static int getSecurity(WifiConfiguration config) {
if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK))
return SECURITY_PSK;

if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) || config.allowedKeyManagement.get(KeyMgmt.IEEE8021X))
return SECURITY_EAP;

return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
}

所以...

public static String getSecurityType(WifiConfiguration config) {
switch (getSecurity(config)) {
case SECURITY_WEP:
return "WEP";
case SECURITY_PSK:
if (wifiConfiguration.allowedProtocols.get(WifiConfiguration.Protocol.RSN))
return "WPA2";
else
return "WPA";
default:
return "NONE";
}
}

关于android - 如何从 Android WifiConfiguration 条目获取 WiFi 安全性(NONE、WEP、WPA、WPA2)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28022809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com