4

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.

1 Answer 1

9

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

wifiManager.removeNetwork(k.networkId)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I really don't know how I overlooked that. That fixed it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.