Android - 以编程方式检测wifi是否为WEP,WPA,WPA2等

Jon*_*Jon 10 android wifi

我在Android上寻找一种程序化方式,以确定我的设备当前连接的WIFI是使用WEP,WPA还是WPA2"保护".我尝试过谷歌搜索,我找不到一种程序化的方法来确定这一点.我还查看了TelephonyManager(http://developer.android.com/reference/android/telephony/TelephonyManager.html),它也缺少这些信息.

谢谢,J

Dan*_*ent 19

有一种方法可以使用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
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

参考文献:

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:确定范围内wifi网络的安全类型(不连接它们)

ScanResult功能解读


Tac*_*yon 5

请参阅AccessPointState项目中的课程。您正在寻找的方法是getScanResultSecurity

希望能帮助到你!