Skip to content
Related Articles

Related Articles

How to Push Notification in Android using Firebase In-App Messaging?
  • Last Updated : 01 Mar, 2021

We have seen using Firebase push notifications in Android which is used to send push notifications to our users when our user is online. These notifications are being displayed inside the notifications tab in the top section of our phone. In this article, we will take a look at the implementation of Firebase In-App Messaging to display messages to our users inside our app when the user is actually using the app. In this article, we will take a look at the implementation of Firebase In-App Messaging in Android

Note: If you want to Push Notification in Android using Firebase Cloud Messaging then please refer to How to Push Notification in Android using Firebase Cloud Messaging?

What is Firebase In-App Messaging? 

Firebase In-App Messaging is a service provided by Firebase with the help of which we can engage our app’s active users by sending them notifications in different formats. You send notifications to your users to perform so many actions such as watching any video, read an article and many more. You can create customize notifications such as banners, modals, images and send them to your users. These notifications will help you to engage your users across various platforms. 

 What are the capabilities of Firebase In-App Messaging? 

  • Create custom alert: With the help of Firebase In-App Messaging, we can create custom alert dialogs and send them to our users inside our app. We can send our notifications with custom styling and messages.
  • Send relevant and engaging messages: Firebase In-App Messaging provides you a feature with which we can send messages to users when the user is actually using our app. So this will help us to make instant sell conversion in our app.
  • Target message by audience behavior: As Firebase In-App Messaging works with Analytics so with the help of it we can reach the customers which are highly using our app.

What we are going to build in this article? 

We will be building a simple application in which we will be displaying simple notifications in our Android app with different formats. A sample video is given below to get an idea about what we are going to do in this article. 

Step by Step Implementation

Step 1: Create a New Project



To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Connect your app to Firebase

After creating a new project. Navigate to the Tools option on the top bar. Inside that click on Firebase. After clicking on Firebase, you can get to see the right column mentioned below in the screenshot. Inside this column click on In-App Messaging and then click on connect option you will get to see the below screen. On this screen, we simply have to connect our app to Firebase. 

After connecting your app to Firebase, we have to add the below dependencies in the build.gradle file. 

Step 3: Adding dependencies in the build.gradle file

Navigate to the app > Gradle Scripts > build.gradle file and add the below dependencies in the dependency section. 

// dependency for firebase core.



implementation’com.google.firebase:firebase-core:15.0.2′

// Import the BoM for the Firebase platform

implementation platform(‘com.google.firebase:firebase-bom:26.5.0’)

// Declare the dependencies for the In-App Messaging and Analytics libraries

// When using the BoM, you don’t specify versions in Firebase library dependencies

implementation ‘com.google.firebase:firebase-inappmessaging-display’

// below dependency for firebase analytics

implementation ‘com.google.firebase:firebase-analytics’

After adding the above dependencies now sync your project. Now our app is integrated with Firebase In-App Messaging. Now as we are displaying notifications inside our app, so we have to display notifications inside our applications from the Firebase console. For displaying notifications in our app we will be using a test device because this notification appears after some time interval, so we will be using a test device to display notifications inside our app for testing. Now run your app and open your logcat window from the bottom section and inside Info search for Installation ID. You can get to see the installation ID below screenshot. Search for this “Starting InAppMessaging” in your search box of our Logcat. You will get to see the below screen. 

Copy this test id, we will be requiring this id while sending our notification. Now let’s move towards creating our notifications to be displayed inside our application. 

Step 4: Navigate to Firebase Console and Navigate to In-App Messaging

Browse Firebase Console inside your browser and click on the In-App Messaging tab on the left pane, and you will get to see the below screen. 

After clicking on Create your first campaign it will ask for integration of Firebase Analytics select your analytics account and proceed further. After specifying your Google Account for analytics you will get to see the below screen to design your notification which we want to display. In this article, we will be covering the first type of notification as Card notification which is shown below.

Now in the above image, you will get to see different usages of the fields as we scroll down we will get to see the below screen. 

In the above screen, we are adding a button to perform clicks on our notifications and add action to our button inside our notification. After clicking on the Next option we will get to see the below screen. 

Inside the below screen, we have to add campaign name and description to our campaign we can specify any name and description to our campaign, and now we have to select the app to which we have to send a notification. After selecting your app click on the Next option to proceed further. After clicking on the next option you will get to see the below screen. 

Inside this screen, we have to schedule our notifications when we have to send our notifications to our users. Inside this, we can modify our time and schedule our notification. After scheduling our notification click on the Review option, and you will get to see a pop-up option. Inside this option click on Publish option to publish your notification. Make sure to add your device installation ID for sending your notification. After sending this notification it will take some time to display inside your app. Make sure to close and reopen your app to display your notification. You will get to see the notification in your Android app. 

Output:

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!
My Personal Notes arrow_drop_up
Recommended Articles
Page :