Android 7.0 has introduced a new reply feature to the notification system. Now you may send answers directly through the notification tray, rather than the app itself. This tutorial will explain how to implement this new functionality, as well as provide you with an example app.

Requirements

In order to finalize this tutorial you will need:

  • Android Nougat SDK (API 24)
  • Android Nougat Emulator or a mobile device running Android Nougat
  • Android Studio 2.1+

Prepping up your application

build.gradle

Start by creating a new empty project. Modify the app/build.gradle file to match the example below:

MainActivity.java

Next, let’s create the classes we will need later. In the project view right click on the project package, then “New / Java class“. Select MainActivity as the name of your new class. In the new file paste the code below. Don’t worry about the missing classes, we will be adding them shortly.

ReplyBroadcastReceiver.java

Let’s repeat the above process, this time choosing ReplyBroadcastReceiver as the class name. Open a new file and paste the code:

AndroidManifest

Finally, we have to modify the AndroidManifest to include the newly created Activity, as well as register our receiver. Add the code below to your Application tag.

App showcase

Sending notifications

Running the application will show the default screen. Go ahead and press the Send Notification button. It will run the sendNotification() function from the MainActivity class. As you may see in the screenshot Fig.1 , the newly received notification has the Reply action we designed during notification creation.

Android 7.0 Nougat: Sending notifications - Tutorial App Development
Fig. 1. Sending notifications

Replying to notifications

Clicking the Reply button will cause the answer tray to open, as shown in Fig.2. You may type any answer you like. Pressing the send arrow will cause a reply intent to be sent and consequently caught by the ReplyBroadcastReceiver we created.

Android app development: Nougat 7.0 feature: Replying to a notification
Fig. 2. Replying to a notification

Reply confirmation

After receiving the intent, the ReplyBroadcastReceiver will send a notification on its own, confirming the reply. You can see the example answer in Fig.3.

Andoid direct reply confirmation: Tutorial Nougat 7.0
Fig. 3. Reply confirmation

Android Developer

Android enthusiast, constantly learning anything and everything about mobile technologies.