Can I check if a boradcasting SSID is secured with a key, without attempting to connect to it?
Using WifiManager's getScanResults
method, and check ScanResult's capabilities field value.
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wm.startScan();
//some time after...
List<ScanResult> results = wm.getScanResults();
for( ScanResult result : results ){
//if this ap is locked, the capabilities string should contains..
//the name of encryption mechanism. ex> [WPA2-EAP-CCMP]
Log.v("AP", "AP:" + result.capabilities);
}
In my case, the result log looks like this...
09-16 21:01:41.308 V/AP﹕ AP:[WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]
09-16 21:01:41.308 V/AP﹕ AP:[WPA-PSK-CCMP][WPS][ESS]
09-16 21:01:41.308 V/AP﹕ AP:[WPA2-EAP-CCMP][ESS]
09-16 21:01:41.308 V/AP﹕ AP:[WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS]
09-16 21:01:41.308 V/AP﹕ AP:[WPA2-EAP-CCMP][ESS]
09-16 21:01:41.308 V/AP﹕ AP:[WPA2-EAP-CCMP][ESS]
You may need below permissions in order to scan & read result.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>