Monday 14 November 2016

Firebase Cloud Messaging for Android

Creating an Android Studio Project

  • As we do always 😛 create a new android studio project. Once the project is loaded copy the package name you can get it from the AndroidManifest.xml file.

Getting a Configuration File

firebase cloud messaging tutorial
  • Now put your app name and select your country.
firebase cloud messaging tutorial
  • Now click on Add Firebase to Your Android App.
add firebase to android
  • Now you have to enter your projects package name and click on ADD APP.
  • After clicking add app you will get google-services.json file.

Adding Firebase Messaging to Your Project

  • Now come back to your android project. Go to app folder and paste google-services.json file.
firebase cloud messaging tutorial
  • Now go to your root level build.gradle file and add the following code.
  • Inside app level build.gradle file make the following changes.
  • Now sync your project.

Implementing Firebase Cloud Messaging

  • Create a class named  MyFirebaseInstanceIDService.java and write the following code.
  • Now create MyFirebaseMessagingService.java and write the following code.
  • Now we have to define the above services in our AndroidManifest.xml file. So go to manifest and modify as follows.
  • Thats all. Now run your app (Make sure your device is having google play service or else it won’t work).
  • After running you will see the token in the logcat. Copy the token.
firebase cloud messaging tutorial

Sending Push Notification using Firebase Console

  • Go to firebase console and select the app you created.
  • From the left menu select notification.
  • Click on new message.
  • Enter message, select single device and paste the token you copied and click on send. The same as I did on the video, and check your device
firebase cloud messaging tutorial
Firebase Cloud Messaging Tutorial
  • Bingo! It is working absolutely fine. If you are having trouble then you can get my source code from the link given below.
  • I hope you all like it if any Queries please comment it below.

No comments:

Post a Comment