Android sending notification through your app (via Firebase console)

Updated 26 October 2021

Save

We all love to enable the firebase push notification in our android application.

But while looking at the documents and  prescribed content, one might be confused many a times as in what exactly is the right approach to send a notification.

In this blog, we will learn two ways of sending a push notification to your android application using firbase push notification.

Prerequisite :

  1. Register your application on the firebase console.
  2. Download the google service json file.
  3. Save the server key with you ( this might be required in the second approach).

Now looking at the approaches, the first approach is pretty simple and officially recommended. Lets have a look at this :

Approach 1 :

  1. Put all the content you want to send in a hashmap.
  2. Get an instance of FirebaseMessaging class.
  3. Build an instance of RemoteMessage.Builder class.
  4. Send the notification by using the send method of FirebaseMessaging instance you had.

CODE :

Well, that’s it . You can now send the Push notification.

APPROACH 2 :

  1. Put all your content in a JSON OBJECT .
  2. Create a HTTP request.( you can use any library you wish to i have used VOLLEY).
  3. Change the header of that request.

CODE :

That’s it, the second approach is done.

NOTE: Saving SERVER API KEY in code is not recommended by the FIREBASE.

For getting where exactly thye serverkey is on firebase console ,you can have a look at this screenshot.

 

author
. . .

Leave a Comment

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


9 comments

  • Muhammad Aashir
    • anchit (Moderator)
      • Muhammad Aashir
        • anchit (Moderator)
          • Muhammad Aashir
          • Muhammad Aashir
          • anchit (Moderator)
  • Snehil Verma
    • anchit (Moderator)
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home