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.
How to integrate FCM into Android Project?
Step for creating Firebase Project
Step 1: Open Firebase console
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.
Step 3: Then select “Add Firebase to your Android app”.
Step 4: Add project package id or application id and genrate SHA-1 signatature of your machine.
Step 5: Download google-service.json and put into app module.
How to generate SHA Key using Android Studio:
- Open your project into Android studio.
- Click on Gradle tab on right side.
- Collapse :app module -> Tasks -> Android -> signing report.
- SHA-1 will generate. Copy and paste into SHA-1 in firebase console.
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
- 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
So that's all for this Firebase Cloud Messaging Tutorial. If any query/suggestion for Firebase Cloud Messaging Tutorial ask freely on hardikdungrani8@gmail.com
Thanks.