本文介绍了如何从Android的WifiConfiguration项获得无线网络的安全性(无,WEP,WPA,WPA2)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从 WifiConfiguration
项安全类型。这可能吗?
I need to get security type from WifiConfiguration
entry. Is it possible?
String getSecurityType(WifiConfiguration conf) {
}
返回值无,WEP,WPA,WPA2
对于那些谁认为这是一个重复的问题:我想从 WiFiConfiguration
对象的信息,而不是从 ScanResult
对象。这是不一样的!
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!
推荐答案
我能做到这一点,简单地说:
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";
}
}
这篇关于如何从Android的WifiConfiguration项获得无线网络的安全性(无,WEP,WPA,WPA2)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!