Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if ScanResult network is already configured (exists in getConfiguredNetworks() list)

I need to check for every network returned by getScanResults() method if it is already configured in the device, that is, I need to check if it exist in the list returned by getConfiguredNetworks(). The problem is: how can I do this since the only parameter they have in common is SSID? I know this wouldn't be the good way to do it because there could be more networks with same SSID. As stated in the reference, networkId is The ID number that the supplicant uses to identify this network configuration entry, but I can't find something similar for the ScanResult object.

So if this is my receiver:

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
registerReceiver(new BroadcastReceiver()
       {
           @Override
           public void onReceive(Context c, Intent intent) 
           {
              results = wifi.getScanResults();
              size = results.size();
           }
       }, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); 

and this is how i get the configured networks:

List<WifiConfiguration> list = wifi.getConfiguredNetworks();

Is there a way to check if list.get(i) corresponds to results.get(j) configuration, for whatever i or j?

like image 643
samugi Avatar asked Aug 06 '13 09:08

samugi


1 Answers

You can check if the BSSIDs of both the networks match. ScanResult and WifiConfiguration both supply a BSSID, which is unique to a network.

like image 148
Sreedevi J Avatar answered Sep 19 '22 00:09

Sreedevi J