Here's a link where the answer present!
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
break;
}
}
He is doing disconnect() before enabling particular SSID every time. I followed the same and it is working fine for me.
But the question is why every time disconnect() needed before enable ?