Вопрос

Can i check if a acces points is secured with a key without connecting to it? With this i can place an icon if the wifi ap is locked or not. Many thanks, Tim

Это было полезно?

Решение

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"/>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top