The following short tutorial will cover the instructions on how to receive push notifications from the Firebase console when the application is running in either background or foreground.

You need to create a project using Firebase console.

Create a new project, download the configuration file and add it to the application.

Add the Google messaging service to the root build.gradle file:

Apply the Google messaging service plugin to your app level build.gradle file:

Add the implementation of the Firebase messaging service and sync the project:

Add the code to fetch the Firebase cloud messaging token:

That’s all that’s needed to receive a push notification when the application is running in the background.

To receive the push notifications in the foreground we need to add a custom service:

And expose it in the AndroidManifest.

This is it! You can find the complete project on GitHub.

%d bloggers like this: