Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Remove WIFI network with certain SSID's

I understand that in Android you have to remove WIFI networks by network ID and not SSID.

However I am trying to remove devices that contains certain phrase in the SSID name.

Say if(k.SSID.contains("ThisWord_")) it would remove that configured network.

I can go through and display all SSID's however I dont know how to compare the SSID to the NetworkId to remove it.

Although as I said it isn't correct, I don't know how to move on honestly.

I have following codes:

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
//        int networkId = wifiManager.getConnectionInfo().getNetworkId();
//        wifiManager.removeNetwork(networkId);
        wifiManager.saveConfiguration();

        List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
        List<String> ThisList = new ArrayList<String>();
        int i = 0;

        for(WifiConfiguration k : list)
        {
            if(k.SSID.contains("ThisWord_"))
            {
                int networkId = wifiManager.getConnectionInfo().getNetworkId();
                ThisList.add(k.SSID);
                i++; 
                wifiManager.removeNetwork(networkId);
                wifiManager.saveConfiguration();
            }
        }

Any help is appreciated.

like image 280
user3465662 Avatar asked Jan 10 '23 22:01

user3465662


1 Answers

Just a wild guess...don't you want to remove the network id associated with the wifi configuration k?

wifiManager.removeNetwork(k.networkId)
like image 98
RichS Avatar answered Jan 16 '23 12:01

RichS