Android: remove WIFI network with specific SSID

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

However, I am trying to remove devices that contain a specific phrase in the SSID.

Say that (k.SSID.contains ("ThisWord_")) this will delete this configured network.

I can go through and display all the SSIDs, but I don’t know how to compare the SSID with NetworkId to remove it.

Although, as I said, this is not correct, I do not know how to act honestly.

I have the 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.

+4
source share
1 answer

... , Wi-Fi k?

wifiManager.removeNetwork(k.networkId)
+9

Source: https://habr.com/ru/post/1533592/


All Articles