android studio workmanager 每天在特定时间一次
我正在尝试制作一个应用程序,每天发出一次网络请求,然后向工作管理器推送通知。
现在,我成功地完成了除了工作管理器调度部分之外的所有事情。
我希望它每天早上 8:00 发生一次,但我不知道如何进行。
目前我正在使用 oneTimeWorkRequest,但如果有更好的选择,我会更改它......
那么您认为解决我的问题的最佳方案是什么?
I'm trying to make an app that make a web request once a day and then push a notification with work manager.
Now, I managed to do everything except the part with the scheduling of the workmanager.
I want it to happen once a day at 8:00 am, but I couldn't figure out how.
Currently I'm using oneTimeWorkRequest, but I'll change it if there is a better option...
So what do you think is the best sulotion for my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
// 在 onCreate 中你只需调用 startWork();您可以根据需要更改 createConstraints() 中的属性
//计算从现在到 8 点之间的时间量(毫秒)
在 NotifyWorker 类中您调用 -sendNotification()
这是一种方法,老式方法是使用 AlarmManagers 和 BroadcastReceiver()...
// In onCreate you just call startWork(); you can change attributes in createConstraints() as you want
//calculate amount of time (milliseconds) between now and 8 hours 'o clock
Inside class NotifyWorker you call -sendNotification()
That is one way to do it, old-fashioned way is to use AlarmManagers and BroadcastReceiver()...