Android


How to add firebase push notification in android

Firebase push notification in android

Firebase is a real-time, advanced and powerful tool for android app development. Firebase is a Google product. This is used for firebase push notification in android and storing data on the cloud, crashlytics, analytics, user authentication, cloud messaging and much more.

In this session, I’ll cover push notification of Firebase. Firebase allows sending real-time messaging on Android phones.

Types of Firebase messaging

  • Notification Message
  • Data Message
  • Notification and Data Message

Using the Firebase messaging you can send Above all types of messages. Let’s see some more information about these three types:

Notification Message:

You need to to set your message only. In other words, Notification messages are handled by Firebase itself.

Data Message Firebase push notification:

Data messages are handled by the Android app.

Notification and Data Message:

In this situation, it will be handled in two scenarios depending upon app state (foreground/background). For these messages, we can use both notification and data keys and their values.

Create your account link for firebase push notification in android

Your can create your account with this Firebase Click here.

Firebase push notification states

  • Foreground State
  • Background State

Foreground State:

App receives a message object with both payloads in activity FirebaseMessagingService.

Background State:

App receives the notification message payload in the notification tray, and when a user taps on the notification then handle the data payload.

After that, The second thing is a message targeting the audience. You can send notification messages either to a single user or to all users using a topic name. But for targeting the audience you need a registered token id. Therefore, I’m going to tell you how to get this token id.

Let’s start with Firebase Sample Project

After that, I’ll tell you how you should use them. Above all steps follow carefully and create your Firebase Project.

Firstly: First of all login with your gmail account in Firebase.

Secondly: You’ll see the Welcome page of Firebase like this

Thirdly: Add project in your account.

Fourthly: Now you’ll see this screen, here you can choose your platform and choose options to add your Firebase android app.

Six: Now you can register your app with package name and your app name.

Seven: When you pressed Register App button, Firebase allows downloading config file to your PC. And this file needs to add in your android project root folder.

Finally: Now, add Firebase SDK in your Gradle file.

Now come to your Project and do some important changes. Add this link to your project level Gradle:

Add this to your add level Gradle:

And bottom of the same file add this line:

Sample file for your Project level Gradle is:

And Your app level Gradle is:

Now create your FirebaseCloudMessagingService file, FirebaseCloudMessagingService.java

MainActivity.java

activity_main.xml

Add sevices of Filebase in your android manifest:

manifest.xml:

Now, go to your google Firebase account and select Notification section to send a notification message.

After this you’ll see this screen to send your first Notification:

Create your first notification like this and press send:

Now you’ll get notification on your phone like this:

When you tap on the notification your app will open:

And for Register Token Id press on GET TOKEN button:

firebase push notification

Published by Amit Pandey

Professional Android app Developer, Full Stack Web Developer, Blogger, Entrepreneur And Founder of Coding Issue. I am always trying to learn new things or new possible ways to do things.

Did you find this page helpful?

X

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

*