Android手机休眠时网络访问
我使用警报(使用 AlarmManager
设置)和后台服务的组合来定期同步应用程序中的数据。
我遇到的唯一问题是,当睡眠策略终止 Wi-Fi 连接时,同步将不再起作用。
有没有办法“唤醒”已进入睡眠状态的 Wi-Fi 连接? GMail 以某种方式设法做到了这一点,因为即使手机进入睡眠模式,它也会通知我有新电子邮件。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[更新]您可以使用 WifiLock 保持 WiFi 活动,同时保持锁定。
使用
AlarmManager
和Service
对我来说,你的服务只运行了很短的时间!?我认为(尽管不能肯定地说)您应该将您的服务设为前台服务(查看博客以了解在 1.x 和 2.x+ 上实现此功能的好方法)并保留AlarmManager出来了。
[update]You can use a WifiLock to keep WiFi active, while holding the lock.
Using an
AlarmManager
and aService
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 theAlarmManager
out of it.