2018 tutorial with updated dependency “Firebase Cloud Messaging and Firebase In-App Messaging “

Hey everyone someday ago someone mail me to make a post about Firebase cloud messaging. So here I am with a new post. In this post we will learn about how to add cloud messaging feature in your application this is a new way like there are so many tutorials available but this is new 2018 way with updated dependency so let’s start…

 First we will learn about how to add firebase cloud messaging to our application after that we will add in-app messaging and we will check all cloud messaging and in-app messaging both are working fine with updated dependency… 

So if you are an experience firebase user then you can directly jump to the coding part but if you are new then don’t miss any part just read full post then add the code to your application otherwise some features may not working or may be the messages will not coining to your application.. 

First thing First open Firebase console and create a project as you know this is a most important part and this is as simple as creating a Facebook account just follow the images bellow… 

Creating a project

Follow the steps below.

1. Open the Firebase console.


You can import an existing Google project to configure FCM if you have added Google features other than FCM to the project.

3. The “Create a project” window opens.
     Enter the following information and click “CREATE PROJECT”.

  • Project name Enter “PushTest”. This is the project name of your app in the Firebase console. You can chose anything you want.
  • Country/region Select your location. 

4. The start screen of the Firebase console opens.
     Click “Add Firebase to your Android app”.

5. The “Enter app details” screen opens.
    Enter the package name of the mobile app here. Specify the package name specified when you        created the project in Android Studio. It is com.example.pushtest in this tutorial.

   You can omit the app nickname and the debug signing certificate SHA-1 if you use only the FCM feature. Otherwise, follow the on-screen instruction.

Click “ADD APP” after specifying the app details.

6. Continue the configuration by following the on-screen instruction.

Image result for adding firebase json file to android project

  • The “Copy config file” screen downloads the google-services.json file to your machine as soon as the screen opens. You will set up the google-services.json file in Android Studio.
  • Ignore the instruction to modify the build.gradle file because the modification instructed on the screen will cause a build error. We will modify the build.gradle file in a later step.

After creating the project you need to create a project in your android studio or if you already create a project and want to work with the old project then open that project in your studio. 

Now paste the downloaded json file in the project app folder as the image shown below… 

Image result for adding firebase json file to android project studio

Now this is the part of adding dependency to our application so open project level gradle file and paste this dependency…

buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:4.1.0' // google-services plugin

allprojects {
    // ...
    repositories {
        // ...
        google() // Google's Maven repository

after adding that now open the app level gradle file and paste this two dependency for adding the features of FCM to our application…

android {
  // ...

dependencies {
  // ...
  implementation 'com.google.firebase:firebase-core:16.0.4'

  implementation 'com.google.firebase:firebase-messaging:17.3.3'
  } // ADD THIS AT THE BOTTOM apply plugin: 'com.google.gms.google-services'

After adding this dependency sync the project…

Now create a java file just right click on the java file and click new and create a new java file and name it as MyFirebaseInstanceIDService now follow the code bellow or just paste the code in your newly created java file. 

NOTE: This code is for all android I tried that code for the minimum SDK of 21 and targeting version is 28 and it will properly working with every version and this is the only java code you need for the firebase messaging service in the old version we have to add one more java file but we are not adding it here… 

Now open your manifest file and add the internet permeation to your application 

<uses-permission android:name=”android.permission.INTERNET”/>

And also add the newly created java file to the manifest add the bellow code to the manifest under the application tag. 

Now you can run your application and test by sending your first cloud message.

Note: This code is properly working if the application is open or in the foreground or even the application is killed in every situation your message will be received. Now send the message by following the bellow images. 

So we successfully add firebase cloud messaging system to our application now we will ad in-app messaging to our application and hear is a twist we don’t need to write a single line of code for this just need to add one dependency and boom! All the work will be done add the bellow line to the app level gradle file and sync the project. 

// ...
dependencies {
    // ...

    // Add the In-App Messaging depencency:
    implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.2'


Now all the coding is finished now run your application and test in-app messaging…If you want the full project then follow the link the full project is available in GitHub

GitHub link-> https://github.com/MonsterTechnoGit/Firebase-Cloude-Messeging-and-Firebase-In-App-Messaging/

Thanks for your time to read this post I will come back with another interesting and important tutorial for now if you have any issues then you can comment it down I will solve your problem.

Posts created 40

Leave a Reply

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

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top