Android的 - 如果检测WiFi是WEP,WPA,WPA2等编程 [英] Android - detecting if wifi is WEP, WPA, WPA2, etc. programmatically
问题描述
我要寻找在Android编程的方式来确定当前是否我的设备连接的无线网络,来的是安全无论是使用WEP,WPA或WPA2。我试过谷歌搜索,我无法找到一个纲领性的方法来确定这一点。我也看了看TelephonyManager( http://developer.android.com/参考/安卓/电话/ TelephonyManager.html ),其中还缺乏这种信息。
I am looking for a programmatic way on Android to determine whether the WIFI my device is currently connected to is "secured" using either WEP, WPA, or WPA2. I've tried Google searching and I cannot find a programmatic way to determine this. I've also looked at the TelephonyManager (http://developer.android.com/reference/android/telephony/TelephonyManager.html) which also lacks this information.
谢谢,
Ĵ
推荐答案
有是使用ScanResult对象的方法。
There is a way using the ScanResult object.
事情是这样的:
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/净/ WIFI / WifiInfo.html
<一个href=\"http://stackoverflow.com/questions/6866153/android-determine-security-type-of-wifi-networks-in-range-without-connecting-t/19567423#19567423\">android:确定范围的WiFi网络的安全类型(无连接到他们)
<一个href=\"http://stackoverflow.com/questions/11956874/scanresult-capabilities-inter$p$ptation\">ScanResult功能间pretation
这篇关于Android的 - 如果检测WiFi是WEP,WPA,WPA2等编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!