开发者

Check for wifi networks signal in sleep mode

开发者 https://www.devze.com 2023-03-22 04:37 出处:网络
My objective is to be able to scan changes in Wi-Fi networks (mainly to check what networks are available). Right know I\'m doing it by registering a reciever:

My objective is to be able to scan changes in Wi-Fi networks (mainly to check what networks are available). Right know I'm doing it by registering a reciever:

registerReceiver(wifiReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));

where WifiReceiver is my BroadcastReceiver.

The problem is that it works only when the phone is on. As soon as it goes to sleep mode (either by pushing the power button or after some time), the receiver stops receiving. I already acquired a wake lock in onCreate of my main class and releasing it in onDestroy (it's a partial wake lock). Additionally I've tried this:

Settings.System.putInt(getContentResolver(),开发者_JAVA技巧Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_NEVER);

to keep wifi from sleeping. Unfortunately that didn't help.

Is there any possibility to scan for network changes, even when phone is asleep? I want to be able to check what networks are in range (by SSID). Maybe I should use another action?

Appreciate your help.


Literally, no, the hardware isn't typically designed nor the low level drivers written to allow wifi to operate while the application CPU is in sleep mode - unlike the case with the mobile network interface which is intended to receive push events like phone calls, sms, and gmail "tickles".

So your choices are to either manage to successfully prevent the device from sleeping (good bye battery) or wake up periodically using an alarm, kick the wifi active, and poll the situation (still not good for battery life, but not as drastically so).


I'm afraid this sleep behaviour is managed by the system under (on Android 2.3.4) Settings > Wireless & Networks > Wi-Fi Settings > Press Menu > Advanced > Wi-Fi Sleep policy.

This could actually go against the users will, careful with that.

However I think there has to be a way to modify this param. programmatically, using this settings : Settings.System, and of course the corresponding permission in your manifest.

0

精彩评论

暂无评论...
验证码 换一张
取 消