views:

266

answers:

1

Right now I'm trying to restart android wifi service after stopping it. I stop the service with the following code:

WifiManager wifiManager = ...;
wifiManager.setWifiEnabled(false);

This disables wifi when there's no lock on the wifi connection. But how do I restart the wifi service? My first approach was the following:

wifiManager.setWifiEnabled(true);

It seems like wifi is enabled after this call but the wifi service doesen't connect to available / in range WLANs. So my question is: What do I have to do to restart the wifi "autoconnect" feature?

Is it enough to just start a scan?

wifiManager.startScan();
+1  A: 

After wifiManager.setWifiEnabled(true); it took few seconds to connect to the network. It seems WifiManager reconnects automatically after call to wifiManager.setWifiEnabled(true)

Suresh