I'm trying to reconnect to the previous WiFi Network(s) after calling WifiManager.setWifiEnabled(false)
and WifiManager.setWifiEnabled(true)
, but I get "unknown SSID". I've tried to use WifiManager.saveConfiguration()
after connecting to the network but nothing. I also tried to get the list of configurations but it was null after re-enabling. I fear that I may be doing it too early possibly? The below code is not in a broadcast receiver, but a checkedchangelistener.
mWifiManager.setWifiEnabled(true);
//the below comments don't work either. I tried.
//List<WifiConfiguration> configuredNetworks = mWifiManager.getConfiguredNetworks();
//if (configuredNetworks != null) {
//for (WifiConfiguration wifiConfiguration : configuredNetworks) {
// }
//}
//get connection info
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
if (wifiInfo != null) {
RelativeLayout currentNetworkLayout =
generateCurrentNetworkLayout(mContext, wifiInfo.getSSID()
.replaceAll("^\"|\"$", ""));
mWifiListLayout.addView(currentNetworkLayout, 1);
}
How do I automatically reconnect to past WiFi network is re-enabled?
Update
It seems to auto-reconnect to last one automatically if you use enableNetwork so no need for saveConfiguration()
. I think my code was wrong before.