日期临近时通知用户 [英] Notify user when a date is near

查看:87
本文介绍了日期临近时通知用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用使用多个Firebase功能的Android应用程序.在实时数据库中,我有一个日期(书的到期日期),当该日期临近时(例如,数据库中日期的前1天),我需要通知用户. Firebase云功能似乎没有特定的触发器来执行此操作,因为数据库中没有任何更改.

我看过 这个线程,它可以为将来的日期设置警报/通知,但是我不知道如何在设置日期后停止它;如果他们还书,我需要取消通知.这确实会触发数据库中的更改,因此,如果可以的话,我将使用一个事件来取消它.

这是执行此操作的最佳方法,还是有使用Firebase实施的方法?如果这是可行的方式,我该如何取消预定的通知?

解决方案

来自您发布的Reddit帖子,请使用诸如 Firebase JobDispatcher (API 9+)或 Evernote的Android作业 (API 14+,但不需要Google Play服务.)

由于Firebase Realtime DB在本地可用,因此您具有要显示通知的日期(可能还有时间).其中一个工作计划程序可以简单地运行一个显示通知的工作,无需互联网或服务器.

此外,建议进行作业调度,因为使用Android Oreo&高于(26岁以上)的用户,后台任务在执行上有更多限制. /p>

I'm currently working on an Android app that uses several Firebase functions. In the Realtime Database I have a date (the date a book is due) and I need to notify the user when that date is near (say, 1 day before the date in the database). Firebase cloud functions doesn't seem to have a specific trigger to do this, as nothing in the database is changing.

I have seen this thread, which can set an alarm/notification for a future date, but I don't know how to stop it once it's been set; I need to be able to cancel the notification if they return the book. This does trigger a change in the database, so I would have an event to use to cancel it, if there was a way to do so.

Is this the best way to do this, or is there a way to implement it using Firebase? And if this is the way to go, how would I cancel a scheduled notification?

解决方案

Coming from the Reddit post you made, use a Job Scheduling tool like JobScheduler (API 21+), Firebase JobDispatcher (API 9+) or Evernote's Android Job (API 14+ but no Google Play Services required).

Since your Firebase Realtime DB is available locally, you have the date (and possibly the time) of when you want to show the notification. One of the job schedulers can simply run a Job which shows a notification, no internet or no server required.

Also, Job scheduling is recommended because, with Android Oreo & above (26+), background tasks have more restrictions on execution.

这篇关于日期临近时通知用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆