Network access when the Android phone is asleep

筅森魡賤 提交于 2019-12-07 04:20:38

问题


I'm using a combination of alarm (set with AlarmManager) and background service to periodically synchronize data in my application.

The only problem I have is that when sleep policy terminates Wi-Fi connection the synchronization no longer works.

Is there a way to "wake up" the Wi-Fi connection that has been put to sleep? GMail somehow manages to do that because it notifies me about new e-mail even if the phone entered sleep mode.


回答1:


[update]You can use a WifiLock to keep WiFi active, while holding the lock.

Using an AlarmManager and a Service says to me your service is running only for a very short time!? I think (though can't say for certain) that you should make your service a forground service (check the blog for a good way to implement this on both 1.x and 2.x+) and leave the AlarmManager out of it.



来源:https://stackoverflow.com/questions/2487008/network-access-when-the-android-phone-is-asleep

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!