简体   繁体   中英

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.

只是一个疯狂的猜测...你不想删除与wifi配置k相关的网络ID吗?

wifiManager.removeNetwork(k.networkId)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM