Skip to content

Hardik8184/FirebasePushNotification

Repository files navigation

Firebase Push Notification Tutorial

How Firebase Push Notification works?

Firebase serves as a module between your server and the devices that will be receiving the push notifications that you create. Your server informs Firebase that a notification has to be sent. Then Firebase does the work behind the scenes to get the notification published.

 

Image 1

How to integrate FCM into Android Project?

Step for creating Firebase Project

Step 1: Open Firebase console

Image 1

Step 2: Click on Add project and give name to your project and select country. If you have already created a project skip this step.

Image 1

Step 3: Then select “Add Firebase to your Android app”.

Image 1

Step 4: Add project package id or application id and genrate SHA-1 signatature of your machine.

Image 1

Step 5: Download google-service.json and put into app module.

Image 1

How to generate SHA Key using Android Studio:

  1. Open your project into Android studio.
  2. Click on Gradle tab on right side.
  3. Collapse :app module -> Tasks -> Android -> signing report.
  4. SHA-1 will generate. Copy and paste into SHA-1 in firebase console.

Image 1

How to integrate Firebase SDK into Android Project?

Step 1:

Add below code into <project>/build.gradle file.

buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:4.3.2'
  }
}

Step 2:

Add below code into <project> / <app>/build.gradle.

dependencies {
  // Add this line
  implementation 'com.google.firebase:firebase-messaging:20.0.0'
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

Step 3:

Press on sync now in the Android Studio.

Now you can send Push Notification using Firebase Console

  1. Go to firebase console and select the app you created.
  2. From the left menu select notification.
  3. Click on new message.
  4. 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

So that's all for this Firebase Cloud Messaging Tutorial. If any query/suggestion for Firebase Cloud Messaging Tutorial ask freely on [email protected]

Thanks.