views:

53

answers:

1

Hi,

By default, Wifi sleep policy is "Sleep on screen idle".

With this policy, is it possible for a Background Service at a later time to wake up Wifi using some API?

Am trying the following, but does not work: When my Background Service wakes up, it calls "ConnectivityManager.getActiveNetworkInfo()" to get active network. Since, the wireless is off on idle, I tried waking it up using "WifiManager.startScan" on a previously used Wifi connection. But still dont get Wifi connectivity.

Any ideas? I preferably do not want to change my sleep policy to "Never".

Thanks Hemant

A: 

There are no real simple solutions for this. To with a high probability ensure you have WIFI connectivity when the phone/screen goes to sleep the best way is to turn it off. Look here for a lot of details - http://wififixer.wordpress.com/

It is important to realize that in sleep mode the Wifi enters a low power mode. This will become tricky then to programmatically check as it might have connectivity to the Wifi but the Wifi connection is too weak or too slow to complete the HTTP request and hence it times out. This would force you to also check the speed of the Wifi connectivity as well as you will have an active network but a pretty lousy one.

Proper handling of the escaping when timeout occurs for the HTTP call you make makes it ok to use but ultimately the only way to have a background thread constantly running to get data is only doable when you have the Wifi mode to never sleep.

It is tricky and not the best way I know. :-( It is however the only path I have found which is reliable enough.

Erik