Reputation: 1035
I have an Android application that wakes up each night and sync some data with our server. If the device put the WiFi in sleep mode after certain time of no use (or screen off), I need a way to wake up Wifi and do the sync and then allow it to return to sleep mode. So here is what I find out:
If the Wifi is in sleep mode, I can see that (by dumpsys) wifi is still enabled, but runState is stopped. So in my code, I would do something like
WifiManager wManager = (WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
wManager.setWifiEnabled(true);
boolean connect = wManager.reconnect();
Log.d(TAG, "connect " + connect);
I don't think setWifiEnabled(true) is necessary because it is still enabled while in sleep. But I did it anyways and there is no harm. But reconnect always return false, meaning that it cannot reconnect the wifi. And of course, dumpsys still shows that runState is Stopped.
Can someone please help me on this issue? What's the right procedure to wake up Wifi and get a working connection?
Thanks in advance!
Upvotes: 3
Views: 2726