我正在寻找Android上的一种程序化方式,以确定我的设备当前连接的WIFI是否已被保护"使用WEP,WPA或WPA2。我已经尝试了Google搜索,我无法找到一种程序化的方法来确定这一点。我还查看了缺少此信息的TelephonyManager(http://developer.android.com/reference/android/telephony/TelephonyManager.html)。
谢谢, Ĵ
答案 0 :(得分:18)
使用ScanResult对象有一种方法。
这样的事情:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> networkList = wifi.getScanResults();
//get current connected SSID for comparison to ScanResult
WifiInfo wi = wifi.getConnectionInfo();
String currentSSID = wi.getSSID();
if (networkList != null) {
for (ScanResult network : networkList) {
//check if current connected SSID
if (currentSSID.equals(network.SSID)) {
//get capabilities of current connection
String capabilities = network.capabilities;
Log.d(TAG, network.SSID + " capabilities : " + capabilities);
if (capabilities.contains("WPA2")) {
//do something
} else if (capabilities.contains("WPA")) {
//do something
} else if (capabilities.contains("WEP")) {
//do something
}
}
}
}
参考文献:
http://developer.android.com/reference/android/net/wifi/WifiManager.html#getScanResults()
http://developer.android.com/reference/android/net/wifi/ScanResult.html#capabilities
http://developer.android.com/reference/android/net/wifi/WifiInfo.html
android: Determine security type of wifi networks in range (without connecting to them)
答案 1 :(得分:4)
请参阅此project中的AccessPointState
课程。您正在寻找的方法是getScanResultSecurity
。
希望它有所帮助!