How to Implement Firebase Push Notification in Your Android App?

During Google I/O 2016 conference, Google announced major improvements to their Firebase product with a lot of features for mobile application developers.

In case if you don’t know about Firebase, then here’s a brief idea about it: Firebase is a Cloud Service Provider, provided by Google, which provides Mobile Backend as a Service (MBaas).

Firebase gives you tool and infrastructure you need to build better mobile app and grow business successfully. It provides its features divided into three groups mainly: Develop, Grow, and Earn.

firebase notifications

What’s even more interesting is the fact that all of these features provided by Firebase will be connected to Analytics. And it doesn’t matter which feature you use, you’ll get Analytics for free.

There are 15 new features in total among which only 4 features are paid. You can check them out from here.

With Firebase, you can quickly sync up your data and make it available on your app.

In simple words, FCM is a cross platform messaging solution which allows users to reliably send and deliver messages at free of cost.

Now, as you probably know that in order to continuously engage your users and keep content fresh, it is important to retain them. And it has now become easier with Firebase Cloud Messaging by sending push notification to all your Android app users anywhere in the world.

In today’s Android app tutorial, you’ll learn how to implement Firebase push notification in Android app.

Want To Create An Android Application?

Validate your app idea and get a free quote.

Let’s Get Started!

👉 Create a new project under the file menu and click on Next.

👉 Now select your form factor and click Next.


👉 In the next tab, Select Empty Activity and proceed further.


👉 In the last tab, write your project Activity name and click Finish.


👉 Now open the Firebase tools in Android Studio 2.2 Tools -> Firebase


👉 Now setup the Firebase cloud notification by following the steps.


👉 Click on the Connect to Firebase button shown in the right panel.


👉 Name your Firebase Project and click on Connect to Firebase.


👉 Next, Add FCM to App module (click on “Add FCm to your app”)



👉 After adding the FCM, Extend FirebaseInstanceIdService.

👉 Add new class and add snippet in Manifest.


//Register Service in manifest for Token Refresh

<action android:name=""/>

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is called when the InstanceID token
* is initially generated so this is where you would retrieve the token.
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
* Persist token to third-party servers.
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
* @param token The new token.
private void sendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.

Now Extend FirebaseMessagingService.

👉 Add new Class and add a snippet in Manifest.


//Register Service in manifest to Receive Message

<action android:name=""/>

public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
* Called when message is received.
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
// [START receive_message]
public void onMessageReceived(RemoteMessage remoteMessage) {

// TODO(developer): Handle FCM messages here.
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());

* Create and show a simple notification containing the received FCM message.
* @param messageBody FCM message body received.
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("FCM Message")
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */,;

👉 Check your project and Access Push notification.



Start Integration in Code

A) MainActivity.Java

//Retrive Data from Firebase Notification

public class MainActivity extends AppCompatActivity {
private TextView tvNotificationDetails;
protected void onCreate(Bundle savedInstanceState) {
private void initControls() {
tvNotificationDetails = (TextView) findViewById(;
private void setNotificationData(Bundle extras) {
if (extras == null)
StringBuilder text = new StringBuilder("");
text.append("Message Details:");
if (extras.containsKey("title")) {
text.append("Title: ");
if (extras.containsKey("message")) {
text.append("Message: ");

B) activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
android:text="Here notification details will be display" />

👉 Once you complete the code. Run the demo. You’ll see a screen like below:


👉 Now, open your Firebase Console and send a push notification. You’ll receive it in the notification bar like below:


👉 Now click on the notification to open it in your demo Firebase project. You’ll have a screen like below:


Want To Develop An Android Application?

Book your free consultation with Android app experts.


This is how you can easily implement app push notifications. If you face any difficulty implementing it in your native Android app, then you can contact our app developers.

You can use the notifications console to compose and send notifications to all supported targets according to your requirements regarding push notification services.

In case you’re not a technical person and wish to add this feature in your Startup app, you can hire Android app developer from us as we’re a leading Android app development company in India. Throughout our 5 years journey, we’ve helped 25+ successful startups to build their mobile apps and build 2000+ mobile applications overall. You can also check our portfolio.

In case, if you still have any query or confusion regarding push notification app development, then you can get in touch with us through contact us form. The consulation is absolutely free of cost. You can grab a free copy of this Firebase demo from Github as well.

Author Bio
Amit Patolia
Amit Patolia
Designation: Android Team Lead

Amit Patolia is an Android Team Lead at Space-O Technologies. He has over 9+ years of experience in Android app development. He has guided to develop over 100 Android apps with unique features and functionalities. He also has expertise in Kotlin-based apps.