Firebase Cloud Messaging - Android Studio Setup

Firebase Cloud Messaging is best feature offered by Google Firebase Using Firebase Cloud Messaging (FMC) you can see push notification to you user using Firebase Console

Firebase Cloud Messaging - Android Studio Setup
(Logo Credit : Firebase)

If you developing a Android or iOS Apps that you definitely need a push notification service for you application to keep engage with your users and keep them update with you apps. Pushing Notification Is so easy. their are so many service provider give you free service to implement push notification on you android app or iOS app


Push Notification is really important  part of app development. relevant notification at the right moment you can bring users interest and pull them back into your app

Android has different classes for creating notification on-device. the most compelling notification are triggers externally. if you've developing a mobile game then you could spark user's interest by notifying them about games feature and upcoming updates
In this article I'll show you how you can implement firebase notification in you application its so easy and quickly send notification from an external server using FCM (Firebase Cloud Messaging )
We are going to learn how you can create more engaging notification by using Firebase Console. including sending a notification to a single device using their unique token ID


What is Firebase Cloud Messaging?


Firebase Cloud Messaging is completely free cross-platform messaging solution that help to send push notification to you users without having to worry about the code on server. By using firebase console you and send push notification easily and check Real-time data and analyse about your users who click on notification just like this (See Screenshot)

you can also use FMC upstream notifications where to notify your app when their new data available to download it.

FMC have two type of messages:

 

  • Notification Messages. if our app will behave diffremtly depends on wheter app is running on background or in foreground when it receive the FCM message if you app is running in background then the Firebase SDK will automaticall process the message and display your notificaton in users device with system tray that android system is build for you this is the easiest way to send push notification to your users. if your app is running on background or foreground.
  • Data message. like Notification message you can use data messages to send custom notification or elements to the yours Firebase Cloud Messaging place a 4KB limit on the data messages so if your payload exceed 4KB then you need to fetch additional data using work manager. in this tutorial we will be focusing on notification messages.

 

Adding Firebase to your Android project


For more inforamtion about add firebase to your project Read This Article Click Here


Follow This Steps Carefully to add FCM to you android project

Open Firebase Console.
Select “Add project,” and give your project a name.
Read the terms and conditions. If you’re happy to proceed, then select “I accept…” followed by “Create project.”
Select “Add Firebase to your Android app.”
Enter your project’s package name, and then click “Register app.”
Select “Download google-services.json.”
In Android Studio, drag and drop the google-services.json file into your project’s “app” directory.
Open your project-level build.gradle file and add the following:

 

Java
classpath 'com.google.gms:google-services:4.0.1'

 

Open your app-level build.gradle file, and add the Google services plugin, plus the dependencies for Firebase Core and FCM:

PHP
//Add the Google services plugin//
apply plugin: 'com.google.gms.google-services'



dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
//Add Firebase Core//
   implementation 'com.google.firebase:firebase-core:16.0.1' //change to latest version
//Add FCM//
   implementation 'com.google.firebase:firebase-messaging:17.3.4' //change to latest version

After that sync your project and wait until you project sync. after your project successfully sync run on your android studio emulator let the firebase know you app is connected to firebase after running you app if you successfuly add firebase into you app the Congraluation let's move forward

 

Sending your first push notification with Firebase

For Sending your first push notification using Firebase Follow This Steps:

Make sure your app is installed and running in the background, and that your device has an active Internet connection.

In the Firebase Console, select “Cloud Messaging” from the left-hand menu.

Select “Send your first message.” Give your message a title and some body text, and then click “Next.”

Open the “Select app” dropdown, and choose your application from the list. This section also includes some advanced options that you can use to create targeted notifications, based on factors such as app version, the device’s locale, and the last time the user engaged with your app. We won’t be using any of these options in our test notification, but if you want to see what’s available, then select “and…” and explore the subsequent dropdown.

Once you’ve finished editing this section, click “Next.”

Assuming you want to send this message immediately, open the “Send to eligible users” dropdown and select “Now.”

In the bottom-right of the screen, click “Publish.”

Check all the information in the subsequent popup, and if you’re happy to proceed then select “Publish.”

Once all these this after few movement you are able to send push notification on you android app on easy way and this is totally free.