Group Services: Technology Consulting
phone +91-9999-283-283/9540-283-283
email info@sisoft.in
Firebase Logo

Android Firebase Push Notification Integration

What is Firebase ?

Firebase is a mobile and web application development platform developed by Firebase, Inc. in 2011,then acquired by Google in 2014.It helps you quickly develop high-quality apps and grow your business. Some of the important products that it offers are -

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.

In this blog, we will be discussing how can we integrate Android Apps with Firebase Cloud Messaging(FCM). We will be sending a notification message to our Android App from FCM Console. Steps to develop this can be summarized below -

Used Concepts & Used Version: (Version of Android API, Twitter API)

We will be using google-services.json here which is provided by Firebase(Downloaded Earlier).

Now, let’s begin the development...

1.Create a Firebase project

Picture 1 Picture 2 Picture 3 Picture 4

google-services.json

You need to include this directory in your app. Refer to below screenshot to find out the exact location of the directory.

Put Manifest entries in your app for services to be used

Main Activity

There is no change to be done in MainActivity.class for this project. Also, no change in layout for the activity- MainActivity.class

We added 2 services here which will help us to generate token and receive messages coming from Firebase console.

MyFirebaseInstanceIDService

Create MyFirebaseInstanceIDService in the project. This service generates token which is used by firebase Console to send messages to a particular device. Every device generates its unique token which enables single device targetted messages.

MyFirebaseMessagingService

This service is responsible for receiving the notification message from the Firebase console.

onMessageReceived(RemoteMessage remoteMessage) is called once the message is received and we will be calling sendNotification(remoteMessage.getNotification().getBody()) inside it to prepare a notification.

Sending Message from Firebase Console

Visit Firebase Console and click on the Notification tab at the left margin.

Click on the Create Message button to start creating a message.

Compose the message, Select target as Single device and enter the token in the FCM Token registration field to sendthe message. The device will receive the message like a notification.