Skip to content

Instantly share code, notes, and snippets.

@shreyakupadhyay
Created May 9, 2020 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shreyakupadhyay/e4074c3dcd5067fb71d71f843ac0c6df to your computer and use it in GitHub Desktop.
Save shreyakupadhyay/e4074c3dcd5067fb71d71f843ac0c6df to your computer and use it in GitHub Desktop.
// Push Notifications constants
let baseNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
})
.setSound("default")
.android.setChannelId('channelId') // id you have set in HandleNotifications.js
.android.setColor('#ffffff') // you can set a color here
.android.setPriority(firebase.notifications.Android.Priority.High)
.android.setSmallIcon('ic_launcher')
.android.setAutoCancel(true);
// notification actions
const takenAction = new firebase.notifications.Android.Action('medicine_taken', 'default', 'Taken');
const snoozAction = new firebase.notifications.Android.Action('snooz', 'default', '30 min Later');
// creating notification
const bigText = "Please take Medicine on time. Have you already taken it?";
baseNotification
.setNotificationId('reminder')
.setTitle('Reminder')
.setBody(bigText)
.setData({medicineId: '2'})
.android.addAction(takenAction) // adding
.android.addAction(snoozAction); // snoozing
const schedule = {
fireDate: new Date().getTime(),
};
// scheduling notifications
firebase.notifications().scheduleNotification(baseNotification, schedule);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment