Send Push Notifications to Android with Firebase Using Android Studio

So lets start :-

Before We Start

You'll need the following:
  • The latest stable Android Studio
  • A Firebase account

1. Get started

Add a new project or import an existing project to Firebase console.


enter image description here
If you choose to create a new project, you need to set the project name and country. For example, I will call  project FirebaseDemo.

enter image description here 


Then select "Add Firebase to your Android app".

enter image description here
Set a package name for your app. I only set my package name

Click the ADD APP button here to download google-services.json. This is an important file and you will need to put it into your app.

2. Add google-services.json to your app folder

 

Replace the google-services.json in your app folder. The Google services plugin for Gradle will load the google-services.json file you just downloaded.

3. Configure gradle files

 

Open Android Studio and modify your build.gradle files to use the Google services plugin.
enter image description here

 

Now Update the project-level build.gradle 

 

Add the following line to the build.gradle file:



Now Update the app-level build.gradle 

Add this line to the bottom of the build.gradle file




4. Add services to your app

Two services(java Activity) will be added to use  Messaging service both are given below

(1) FirebaseMessagingService.java

To be able to receive any notification in your app, you should add a service which extends FirebaseMessagingService like this:



(2) FirebaseInstanceIdService.java


Add it into the AndroidManifest.xml file


5. Test and send your first push notification!

To see if the setup works, run a test by sending a test message to your own mobile.
enter image description here
Write down your message and choose an app. Click "SEND MESSAGE".

If the setup is successful, you should get a notification on your mobile.

That's All for this post and  Thanks for visiting and thanks for your time if you have any suggestions and want to share any feed back then comment down below and if you face any issue then let me know in the comment section also share this with your friends