2

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.

John61590
  • 1,106
  • 1
  • 13
  • 29
  • Did you check this question - https://stackoverflow.com/questions/8818290/how-do-i-connect-to-a-specific-wi-fi-network-in-android-programmatically ? – Anatolii Jul 12 '18 at 20:12
  • @Anatolii I can connect to it fine, but I just can't reconnect. – John61590 Jul 12 '18 at 20:16

0 Answers0