Firebase Push Notification in Your Android App

Firebase Push Notification in Your Android App

In this tutorial you will learn how to send Push Notification with Firebase Console step by step with screenshot.

Firebase – a cloud platform with a lot of amazing features for mobile app developers. In recent times, Google moved from Google Cloud Messaging (GCM) to Firebase Cloud Messaging (FCM). One of them is Firebase Cloud Messaging (FCM) — In case if you don’t know about Firebase, a cross-platform messaging solution that lets users reliably deliver messages at no cost. Firebase gives you tool and infrastructure you need to build better mobile apps and grow business successfully. Yes, FCM is a free service from Google. Comparing to the earlier Google Cloud Messaging (GCM), FCM is much more developer-friendly because you don’t even need to see any of the server code involved.

Firebase Notification:

Notification messages are handled by firebase SDK itself. Typically the notification message contains title, message, icon etc., These message can be sent from firebase console UI. By sending this kind of messages, you won’t get much control over the notification. The notification will be shown automatically when the app is in background.

In order to send notification message, you need to use notification key in json data. An example of notification message is given below.

Integrate Firebase Cloud Messaging Project:

Step-1 Open firebase console link is -> https://console.firebase.google.com/

Step-2 (Screenshot-1) Register/login with your google account, if you are logged in already then click on “Add project”.

Screenshot-1

Step-3 (Screenshot-2) After clicking on Add project, you will see a popup window “Create a project”. In this popup you will fill project name like mine is ‘coderhold’, so you can put yours. In “Country/region” field you will fill your country or region. and click on “CREATE PROJECT” button.

Screenshot-2

Step-4 (Screenshot-3) After clicking on “CREATE PROJECT” button, then click on “Add Firebase to your Android app”  button. After clicked a popup will open.

Screenshot-3

Step-5 (Screenshot-4) This popup will ask your “Android package name”, this is your android app package name which you created. In “App nickname” field, you will put your app name like mine is coderhold app. In “Debug signing certificate SHA-1” filed you will put your app signing certificate, if you have then put it, otherwise leave it blank, and click on “REGISTER APP” button.

Screenshot-4

Step-6 After clicking on “REGISTER APP” button. Click on “Download google-services.json” button. This will download your json file. After downloaded this file. Switch to the Project view in Android Studio to see your project root directory, given in screenshot. Then Move the google-services.json file you just downloaded into your Android app module root directory.

Screenshot-5

Step-7 After previous step (Step-6) click on “CONTINUE” button. then you will see next step of this popup.

Step-8 (Screenshot-6) follow the instruction in popup, if you can’t understand then follow step-9.

Screenshot-6

Step-9 (Screenshot-7) we have to add Firebase to our app and modify gradle files. At the project level let’s modify gradle fille as:

Screenshot-7

and at the app module build.gradle file add this below line (Screenshot-8). click sync button after this process.

Screenshot-8

Step-10 (Screenshot-9) Now go to Tools->Firebase and you will see ‘firebase assistance’, right hand side in your android studio window. then click on “Cloud Messaging” arrow.

Screenshot-9

Step-11 (Screenshot-10) after clicked arrow, you will see ‘Set up Cloud Messaging’ link. click on that link.

Screenshot-10

Step-12 (Screenshot-11) After clicked on ‘Set up Cloud Messaging’ link, you will see ‘Connect to Firebase’ button. after clicking you will login into your firebase account.

Screenshot-11

after this you will see green marked Connected text, it means you are connected (Screenshot-12).

if we successfully done with all work then 2nd option which is “Add FCM to your app” will be green as well. If not then click on that button and follow instruction.

Step-13 Now add new class “MyFirebaseInstanceIDService.java” .

Note: If red lines error appears then click on red line codes and press Alt+Enter. (for android learners).

now add snippet in Manifest file.

Step-14 Now add new class “MyFirebaseMessagingService.java” .

Note: If red lines error appears then click on red line codes and press Alt+Enter, and in the last, logo line

will give this kind of error so copy your logo.png to drawable folder and error will be disappear. (for android learners).

now add snippet in Manifest file.

Now run your project and Access Push notification.

Step-15 (Screenshot-12) Now go to your firebase console and click on your created project.

Screenshot-12

then you will see this window (Screenshot-13) and click on notification button.

Screenshot-13

Step-16 After clicked on “Notofications”, you will see this window (Screenshot-14) and click on “SEND YOUR FIRST MESSAGE” button.

Screenshot-14

Step-17 (Screenshot-15) Now you will see this window, put your ‘Message text’, ‘Message label’, ‘Delivery date’, ‘Target’, ‘Target user if’, and now click on “SEND MESSAGE” button.

Screenshot-15

You’ll receive it in the notification bar like below:(Screenshot-16).

Note: Sometimes, it can take a couple of minutes for the message to send and arrive, so just be patient for a little while and make a coffee after that check your mobile notification bar. 🙂

Screenshot-16

Congratulations!!  If you face any difficulty implementing it in your Android app, then you can contact our developers team. Now you have the basic idea on how to send push notifications on Android with Firebase. Good luck with your project!

2 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.