Firebase Push Notifications

Now google has shifted its Google Cloud Messaging to Firebase. So I am making this article on how to add Firebase Push Notifications in Android Application. Adding Firebase Push Notifications to android is very easy task Just add two class files and few permissions in AndroidManifest.xml and few line in Gradle files. That’s it your Firebase Push Notifications in Android is set to go.

Procedure :

Adding Firebase Push Notifications to Android involves two parts.

  1.  Setting up Firebase project in your Firebase Console (Watch Video above to know how to do it)
  2. Setting up your Android Studio Project (Follow to next step after doing the first step).
  • You can continue this procedure to your existing Android Studio project.
  • Copy google-services.json to your App folder in your project. (watch Video above to know how to get this file).
  • Next, add below line to Project Gradle file

  • after adding above line code should like in below Image

firebase-android-pushnotifications

  • Now add below dependencies in app Gradle file

  • And also add below line at the end of Gradle file.

  • After adding above line code should look below Image

Firebase Push Notifications

 

  • Android Studio will prompt you with Sync Now sync the project.
  • Next, add Internet Permission to your AndroidManifest.xml file.

  • Now add below services to your Manifest file in between application tags.

 

  • In above code change com.androidmkab.firebase.app to your package name. After adding above codes your Android Manifest file should look like below Image.

  • Now create a new class file with Name MyFirebaseInstanceIdService and add below code to it by replacing everything except the first line which will show your package name.

  • Now create another class file with name MyFirebaseMessagingService and below code to it same as above.

  • Now run the code in your Android Device or Emulator (Make sure Google Play Services are supported if you are using the emulator)  after the app is launched on your device or emulator, go to Firebase Console and send notifications Lala.. you successfully sent and received Firebase Push Notifications.

Sharing is Caring