Changes

Jump to: navigation, search

An Android 7 Direct Reply Notification Tutorial

12 bytes added, 18:31, 18 August 2016
no edit summary
With the Button widget selected in the layout, use the Properties tool window to set the onClick property to call a method named sendNotification().
<htmlet>androidstudio_a7</htmlhtmlet>
== Building the RemoteInput Object ==
}
</pre>
<htmlet>androidstudio_a7</htmlhtmlet>
Now that the RemoteInput object has been created and initialized with a key and a label string it will need to be placed inside a notification action object. Before that step can be performed, however, the PendingIntent instance needs to be created.
}
</pre>
<htmlet>androidstudio_a7</htmlhtmlet>
At this stage in the tutorial we have the RemoteInput, PendingIntent and Notification. Action objects built and ready to be used. The next stage is to build the notification and issue it:
Tap the Reply action button so that the text input field appears displaying the reply label that was embedded into the RemoteInput object when it was created.
<htmlet>androidstudio_a7</htmlhtmlet>
[[File:Android studio direct reply notification reply.png|An Android 7 Direct Reply Notification]]
After making these code changes build and run the app once again. Click the button to issue the notification and enter and send some text from within the notification panel. Note that the TextView widget in the DirectReplyActivity activity is updated to display the inline text that was entered.
<htmlet>androidstudio_a7</htmlhtmlet>
== Updating the Notification ==
The direct reply notification feature allows text to be entered by the user within a notification and passed via an intent to an activity of the corresponding application. Direct reply is made possible by the RemoteInput class, an instance of which can be embedded within an action and bundled with the notification. When working with direct reply notifications, it is important to let the NotificationManager service know that the reply has been received and processed. The best way to achieve this is to simply update the notification message using the notification ID provided when the notification was first issued.
<htmlet>androidstudio_a7</htmlhtmlet>

Navigation menu