diff --git a/docs/html/preview/features/notification-updates.jd b/docs/html/preview/features/notification-updates.jd index d3042ada1f259..7ee09547d06fb 100644 --- a/docs/html/preview/features/notification-updates.jd +++ b/docs/html/preview/features/notification-updates.jd @@ -78,7 +78,7 @@ action. This class's constructor accepts a string that the system uses as the ke of the input.
-// Key for the string that's delivered in the action's intent +// Key for the string that's delivered in the action's intent. private static final String KEY_TEXT_REPLY = "key_text_reply"; String replyLabel = getResources().getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY) @@ -90,7 +90,7 @@ RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY) object to an action usingaddRemoteInput().-// Create the reply action and add the remote input +// Create the reply action and add the remote input. Notification.Action action = new Notification.Action.Builder(R.drawable.ic_reply_icon, getString(R.string.label), replyPendingIntent) @@ -102,8 +102,8 @@ Notification.Action action =
-// Build the notification and add the action
-Notification notification =
+// Build the notification and add the action.
+Notification newMessageNotification =
new Notification.Builder(mContext)
.setSmallIcon(R.drawable.ic_message)
.setContentTitle(getString(R.string.title))
@@ -111,10 +111,10 @@ Notification notification =
.addAction(action))
.build();
-// Issue the notification
+// Issue the notification.
NotificationManager notificationManager =
NotificationManager.from(mContext);
-notificationManager.notify(notificationId, notification);
+notificationManager.notify(notificationId, newMessageNotification);
+ To receive user input from the notification interface to the activity you + declared in the reply action's intent: +
-To receive user input from the notification interface to the activity you -declared in the reply action's intent:
+Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);+
The following code snippet illustrates how a method retrieves the input text -from a bundle:
- -
+
// Obtain the intent that started this activity by calling
// Activity.getIntent() and pass it into this method to
// get the associated string.
@@ -164,21 +166,43 @@ from a bundle:
private CharSequence getMessageText(Intent intent) {
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput != null) {
- return remoteInput.getCharSequence(KEY_TEXT_REPLY);
- }
+ return remoteInput.getCharSequence(KEY_TEXT_REPLY);
+ }
return null;
}
+ Apps can apply logic to decide what actions to take on the retrieved -text. -For interactive apps (like chats), provide more context in the notification itself - (for example, multiple lines of chat history, including the user’s own messages) - so that the user can respond appropriately. -When the user responds via {@link android.support.v4.app.RemoteInput}, - include the text in the reply history with the {@code setRemoteInputHistory()} - method.
++// Build a new notification, which informs the user that the system +// handled their interaction with the previous notification. +Notification repliedNotification = + new Notification.Builder(context) + .setSmallIcon(R.drawable.ic_message) + .setContentText(getString(R.string.replied)) + .build(); + +// Issue the new notification. +NotificationManager notificationManager = + NotificationManager.from(context); +notificationManager.notify(notificationId, repliedNotification); ++
+ For interactive apps, such as chats, it could be useful to include additional + context when handling retrieved text. For example, these apps could show + multiple lines of chat history. When the user responds via {@link + android.support.v4.app.RemoteInput}, you can update the reply history + using the {@code setRemoteInputHistory()} method. +
Android N provides developers with a new way to represent