Cloud Functions to fire a push notification

So far, we have explored features, functionalities, and so on. Now, it's the time to put all our learning into practice. In this example, we will use the blood bank project from Chapter 1Keep It Real – Firebase Realtime Database and add the notification feature using functions. Whenever the database has a new entry, meaning whenever people add their donor details, we will get a notification of what blood group has been added. 

  • Go to the Realtime Database chapter code. Open it in Android Studio.
  • Create the MessagingService class shown next. 
  • Register the service class in the manifest. 
  • Subscribe to the topic in the activity. 

Use this code for the MessagingService class:

package com.ashok.packt.realtime.database ...

Get Mastering Firebase for Android Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.