12

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.

Thanks, J

Jon
  • 1,381
  • 3
  • 16
  • 41
  • 1
    Have you tried looking through [WifiManager](http://developer.android.com/reference/android/net/wifi/WifiManager.html) or [ConnectivityManager](http://developer.android.com/reference/android/net/ConnectivityManager.html)? – VERT9x Mar 06 '15 at 18:53
  • 1
    For the current network you can find what you need in the WifiConfiguration of the WifiManager http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html – Dave S Mar 06 '15 at 19:17
  • have you got solution for this ? – sureshbabu Oct 11 '21 at 08:06

1 Answers1

22

There is a way using the ScanResult object.

Something like this:

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
            }
        }
    }
}

References:

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)

ScanResult capabilities interpretation

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137