Android:如何从 AlarmManager 唤醒 WIFI(或 3G)?
我有这个应用程序需要每 30 分钟从服务器提取数据,经过大量搜索后我找到了这个解决方案: 1- 使用 AlarmManager 每 30 分钟通知应用程序一次,而不是让服务在后台运行。 2-使用带有 PARTIAL_WAKE_LOCK 的唤醒锁
我唯一的问题是 Wifi 在睡眠时关闭。
当我的闹钟被触发时,我如何请求需要互联网连接?
I have this application that needs to pull data from a server every 30 minutes, after a lot of search I reached this solution:
1- using AlarmManager to notify the application each 30 minutes instead of keeping the service running in the background.
2- using wakelocks with PARTIAL_WAKE_LOCK
My only problem is that Wifi is off at sleep time.
How can I request that I need an internet connection when my alarm is triggered??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
前段时间我也遇到了完全相同的问题。不幸的是我没有成功。我尝试了以下方法:
也许您可以使用 WifiManager并找到一种我没有找到的方法。哦,是的,别忘了在清单中设置 WIFI 权限。
干杯卢卡斯
I had exactly the same problem some time ago. Unfortunately I did not succeed. I tried the following:
Maybe you can play around with the WifiManager and find a way that I didn't find. Oh yea, don't forget to set the WIFI permissions in the manifest.
Cheers Lukas
reconnect()
、reassociate()
以及所需的任何内容(这可能是特定于设备的)骨架代码:https://stackoverflow.com/a/19968708/281545
reconnect()
,reassociate()
and whatever is needed (this may be device specific)Skeleton code : https://stackoverflow.com/a/19968708/281545
Android 6(API 级别 23)及更高版本的注意事项。
自从 Google 推出了针对打瞌睡和应用程序待机进行优化以来,事情变得更加复杂。看这里——
https://developer.android.com/training/monitoring-设备状态/doze-standby.html
现在,强制在特定时间访问网络要困难得多。
Note for Android 6 (API level 23) and above.
Since Google introduced Optimizing for Doze and App Standby, things are getting more complicated. Look here -
https://developer.android.com/training/monitoring-device-state/doze-standby.html
Now it is much harder to force access to the network at a specific time.