Search code examples
androidandroid-wifiwifimanager

Getting whether the wifi connection is locked(password protected) or not


In my app I am getting all available WiFi networks and displaying them in a list using WifiManager.startScan() and WifiManager.getScanResults().Also I am able to show signal strength.But I don't know how to show whether wifi is locked or not.In the Settings screen it shows lock icon for wifi which are locked.How can i know whether wifi is password protected?


Solution

  • See ScanResult.capabilities

    An example is: [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP-CCMP][WPS][ESS]

    See this answer if you want to find a way of parsing it.

    Basically, if you want to get if it is protected or not:

    boolean isProtected = AccessPointState.getScanResultSecurity(scanResult) != AccessPointState.OPEN;
    

    (although it is not nice to compare Strings with the == operator, this will always return the correct answer because the reference in AccessPointState is a static final one)