我需要从WifiConfiguration
条目获取安全类型。有可能吗?
String getSecurityType(WifiConfiguration conf) {
}
返回值"NONE", "WEP", "WPA", "WPA2"
对于那些认为这是一个重复问题的人:我想从WiFiConfiguration
对象获取信息,而不是从ScanResult
对象获取信息。它不一样了!
答案 0 :(得分:7)
我能做到,只是:
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";
}
}