Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notify user when a date is near

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?

like image 972
Vedvart1 Avatar asked Nov 12 '17 17:11

Vedvart1


2 Answers

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.

like image 200
Kartik Arora Avatar answered Oct 07 '22 00:10

Kartik Arora


If you are comfortable using Python, then read this post ->

How to Schedule (Cron) Jobs with Cloud Functions for Firebase to create some Firebase cloud functions

My suggestion would be to use the daily-tick function to scan through your Firebase realtime database to retrieve all the books that are "due the next day's date" and issue notifications to them.

It should meet your requirement in a pretty straightforward way. Alternatively, you may try a different method as suggested in the Firebase video here Timing Cloud Functions for Firebase using an HTTP Trigger and Cron - Firecasts

Let me know if neither of these meet your requirements. And what am I missing. I will be glad to recommend a better alternative based on your feedback

like image 45
Abhishek Avatar answered Oct 06 '22 23:10

Abhishek