Ron
Ron

Reputation: 369

How to find all WiFi networks that are not in range?

I am writing an application to display the WiFi network types and status. How do I find all the "not in range" WiFi networks? Is it possible to get the list of all configured (previously seen) WiFi networks that are out of range?

I used the below code to get the result

    WifiManager mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
    List<ScanResult> results = mWifiManager.getScanResults();
    if (configs != null) {
        for (WifiConfiguration config : configs) {
            for (ScanResult result : results) {
                if (result.SSID  == null || result.SSID.length() == 0) {
                    continue;
                }

                else {
                    if (result.SSID.equals(MyString.removeDoubleQuotes(config.SSID))) {
                        int level = mWifiManager.CalculateSignalLevel(result.level, 4);
                        Log.d("MyApp", Config.SSID + "  " + level);
                    }
                }
            }
        }
    }

But if configured network is high in number then it will take long time to execute. Is there any way to optimize this problem? By getting the scanned result of only the configured network.

Upvotes: 1

Views: 2613

Answers (1)

rafalotufo
rafalotufo

Reputation: 3932

How about subtracting the wifi networks in range from all wifi networks?

Upvotes: 3

Related Questions