Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created December 13, 2019 08:03
Show Gist options
  • Save PatilShreyas/7f68252b8a8eb33e77de858d6e2f7454 to your computer and use it in GitHub Desktop.
Save PatilShreyas/7f68252b8a8eb33e77de858d6e2f7454 to your computer and use it in GitHub Desktop.
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
// Check if message contains a data payload.
remoteMessage.data.isNotEmpty().let {
Log.d(TAG, "Message data payload: ${remoteMessage.data}")
// Get Message details
val title = remoteMessage.data["title"]
val message = remoteMessage.data["message"]
// Check that 'Automatic Date and Time' settings are turned ON.
// If it's not turned on, Return
if (!isTimeAutomatic(applicationContext)) {
Log.d(TAG, "`Automatic Date and Time` is not enabled")
return
}
// Check whether notification is scheduled or not
val isScheduled = remoteMessage.data["isScheduled"]?.toBoolean()
isScheduled?.let {
if (it) {
// This is Scheduled Notification, Schedule it
val scheduledTime = remoteMessage.data["scheduledTime"]
scheduleAlarm(scheduledTime, title, message)
} else {
// This is not scheduled notification, show it now
showNotification(title!!, message!!)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment