0

So i'm migrating to FCM HTTP v1 to send notification. But does it comes with scheduled notification configuration?

I want to send notification, for example like one hour from now (for use case like reminder).

In earlier version, like exampled here, you can just provide configuration like this:

{ 
  "to": "/topics/discount-offers", 
  "priority": "high",
  "data" : {
    "title" : "TITLE_HERE",
    "message" : "MESSAGE_HERE",
    "isScheduled" : "true",
    "scheduledTime" : "2019-12-13 09:41:00"
  }
}

But after reading the documentation, I don't think there's variable to configure scheduled notification.

Jimly Asshiddiqy
  • 335
  • 4
  • 15

1 Answers1

3

The Firebase Cloud Messaging API to send messages doesn't support (and has never supported) a way to schedule the delivery of messages. If you want to schedule the display of a notification, you will need to:

  • Either run a server-side component that does the scheduling, and calls the FCM API at the right time.
  • Or call the FCM API right away, but then hold the message in your application code on the receiving device and display the notification when it's time.

The library that you used is an implement of the second option. So the isScheduled and scheduledTime properties are handled by the FCM-OnDeviceNotificationScheduler package, which uses it to schedule a local alarm.

While the v1 API to send messages has changed, you can still pass the exact same data to it - which will then be delivered to the application code on Android, where the library will use it to display the notification at the requested time.

Also see: How can scheduled Firebase Cloud Messaging notifications be made outside of the Firebase Console?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 2
    Thanks for clearing things up, but i have another follow up question. In Firebase Console, there's field for scheduling, how does that work? – Jimly Asshiddiqy Oct 19 '21 at 01:46
  • I like the second approach. It allows displaying the notification even if the device does not have an active internet connection at the scheduled time (assuming it had an internet connection previousley). – Bennik2000 Feb 25 '22 at 18:30