28th Jul 2022

An Overview of Android Smart Replies

Mobile App

Written By, Mahek Thaker

Overview

Hello Android Nerds,

In this blog we will learn more about smart replies notification in Android.

Android smart replies have been quite beneficial when it comes to quickly viewing a particular content and responding to it. They can save time, be efficient and elevate the User experience. Therefore here we have thoughtfully provided a brief overview of Android Smart Replies.

Setup & Instructions

First of all we need to have a project setup in firebase console, you can follow official documentation for that

After you complete setup, move to this messaging tab & click on “New notification”. You will be able to create & test your notification

You’ll also need the FCM token of your device to get your token in order to test the notifications on your device.

That’s it for the setup part let’s move ahead with the smart notifications.

Implementing reply notifications

For implementing reply notifications you need a remote input object which will contain a key with its help you can get your reply message.

Then move on to creating the replyAction which will be passed into your notification after that we will create our PendingIntent, here what flag you pass is very important based on your SDK level so here I had to add a condition for users who are using android 12 or later versions & users below that.

Now to receive the reply message you need BroadCastReceiver which can receive the broadcast when the user clicks on the reply action & sends a reply message then you can make your API call to pass on the reply message, also we need to pass details like name of sender, message, timestamp of message we will use this later in our BroadcastReceiver

MessagingStyle Notification

Here the style NotificationCompat.MessagingStyle is what we need to learn about, it is a recommended style for chat related notifications & it uses a Person object to show name message & other details in notification.

To create an object of Person class it provides us a builder & with that we can set all the values into the object & pass it in the Message object.

Output
output

Conclusion

That’s it for the notification reply, thanks for reading here is the link to source code

Written By,

Android Developer at Yudiz Solutions Pvt. Ltd