2016-10-29

Google announced the new strong product Firebase in Google I/O 2016 . Firebase is a cloud platform with some of amazing feature for android development. Firebase cloud messaging (FCM) is free messaging service from Google that not required any server side code. Earlier google has provided GCM that is Google cloud messaging for push notification which was required server side code to execute the push message. FCM is the new version of GCM.

These are the differences between these two services:

Firebase Cloud Messaging provides a complete set of messaging capabilities through its client SDKs and HTTP and XMPP server protocols. For deployments with more complex messaging requirements, FCM is the right choice.

Firebase Notifications is a lightweight, serverless messaging solution built on Firebase Cloud Messaging. With a user-friendly graphical console and reduced coding requirements, Firebase Notifications lets users easily send messages to reengage and retain users, foster app growth, and support marketing campaigns. If you want a more detailed comparison. Read this.

Lets see the basic configuration

To integrate the Firebase push notification in android we need to follow few steps .

Step.1: Please go to Firebase console to create the project



Step.2: Now you can create the project name and enter your county name. Please refer the below snap.



Step.3: You have to choose which platform do you want to use firebase push. Here we are configuring for android platform, so I am choosing option for android app.



Step.4: Now you need to enter your package name of your project. Ex: Here my package name is "com.sunil.firebasepushnotificationandroid" . Other fields are optional for debug mode. But if you want to release your app that time you need to pass the SHA-1 key.

Step.5: Once you done your step.5 You will get downloded one google-services.json file. You have to copy this file and paste inside the app folder. Please see the below snap to get thing done.

Step.6: Add these dependencies to your build.gradle file.

Wow! you have done the configuration steps completely. Lets focus on code required for push in client side. Firebase push is required two service, one for get the token or registration Id and other for listen the push message to notify to particular device. Here are the details of services.

MyFirebaseInstanceIDService.java

MyFirebaseMessagingService.java

AndroidManifest.xml

These basic code is required for push. Firebase aslo handle itself when the device is in background. It will notify user with push message. Firebase also provide feature for developer to send custom message like title, image, url link etc in json fomate. Developer needs to parse them before notify.

Now here I am not using server side push. So I will push from Firebase console panel.

If you selected push message Send Now. It will push the message to registered devices.

I hope it will help to all newbie developer to implement push notification by using Firebase.

Thanks for your valuable time to reading this post.

Show more