问题
I need to get security type from WifiConfiguration
entry. Is it possible?
String getSecurityType(WifiConfiguration conf) {
}
returning values "NONE", "WEP", "WPA", "WPA2"
For those who think it's a duplicate question: I want to get information from WiFiConfiguration
object and not from ScanResult
object. It's not the same!
回答1:
I can do it, simply:
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;
}
so...
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";
}
}
来源:https://stackoverflow.com/questions/28022809/how-to-get-wifi-security-none-wep-wpa-wpa2-from-android-wificonfiguration-e