Merge "docs: Enhanced description of "direct reply" workflow." into mnc-mr-docs

This commit is contained in:
Kevin Hufnagle
2016-04-12 23:46:53 +00:00
committed by Android (Google) Code Review

View File

@@ -78,7 +78,7 @@ action. This class's constructor accepts a string that the system uses as the ke
of the input. of the input.
<pre> <pre>
// 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"; private static final String KEY_TEXT_REPLY = "key_text_reply";
String replyLabel = getResources().getString(R.string.reply_label); String replyLabel = getResources().getString(R.string.reply_label);
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY) RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)
@@ -90,7 +90,7 @@ RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)
object to an action using <code>addRemoteInput()</code>. object to an action using <code>addRemoteInput()</code>.
<pre> <pre>
// Create the reply action and add the remote input // Create the reply action and add the remote input.
Notification.Action action = Notification.Action action =
new Notification.Action.Builder(R.drawable.ic_reply_icon, new Notification.Action.Builder(R.drawable.ic_reply_icon,
getString(R.string.label), replyPendingIntent) getString(R.string.label), replyPendingIntent)
@@ -102,8 +102,8 @@ Notification.Action action =
<li>Apply the action to a notification and issue the notification. <li>Apply the action to a notification and issue the notification.
<pre> <pre>
// Build the notification and add the action // Build the notification and add the action.
Notification notification = Notification newMessageNotification =
new Notification.Builder(mContext) new Notification.Builder(mContext)
.setSmallIcon(R.drawable.ic_message) .setSmallIcon(R.drawable.ic_message)
.setContentTitle(getString(R.string.title)) .setContentTitle(getString(R.string.title))
@@ -111,10 +111,10 @@ Notification notification =
.addAction(action)) .addAction(action))
.build(); .build();
// Issue the notification // Issue the notification.
NotificationManager notificationManager = NotificationManager notificationManager =
NotificationManager.from(mContext); NotificationManager.from(mContext);
notificationManager.notify(notificationId, notification); notificationManager.notify(notificationId, newMessageNotification);
</pre> </pre>
</li> </li>
@@ -133,30 +133,32 @@ notification action. </p>
<strong>Figure 2.</strong> The user inputs text from the notification shade. <strong>Figure 2.</strong> The user inputs text from the notification shade.
</p> </p>
<h3>Retrieving user input from the inline reply</h3> <h3>
Retrieving user input from the inline reply
</h3>
<p>
To receive user input from the notification interface to the activity you
declared in the reply action's intent:
</p>
<p>To receive user input from the notification interface to the activity you
declared in the reply action's intent:</p>
<ol> <ol>
<li> Call {@link android.support.v4.app.RemoteInput#getResultsFromIntent <li>Call {@link android.support.v4.app.RemoteInput#getResultsFromIntent
getResultsFromIntent()} by passing the notification action’s intent as getResultsFromIntent()} by passing the notification action’s intent as the
the input parameter. This method returns a {@link android.os.Bundle} that input parameter. This method returns a {@link android.os.Bundle} that
contains the text response. contains the text response.
</li>
<pre> <pre>
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
</pre> </pre>
</li>
<li>Query the bundle using the result key (provided to the {@link <li>Query the bundle using the result key (provided to the {@link
android.support.v4.app.RemoteInput.Builder} constructor). android.support.v4.app.RemoteInput.Builder} constructor). You can complete
</li> this process and retrieve the input text by creating a method, as in the
</ol> following code snippet:
<p>The following code snippet illustrates how a method retrieves the input text <pre>
from a bundle:</p>
<pre>
// Obtain the intent that started this activity by calling // Obtain the intent that started this activity by calling
// Activity.getIntent() and pass it into this method to // Activity.getIntent() and pass it into this method to
// get the associated string. // get the associated string.
@@ -169,16 +171,38 @@ private CharSequence getMessageText(Intent intent) {
return null; return null;
} }
</pre> </pre>
</li>
<p>Apps can apply logic to decide what actions to take on the retrieved <li>Build and issue another notification, using the same notification ID that
text. you provided for the previous notification. The progress indicator
For interactive apps (like chats), provide more context in the notification itself disappears from the notification interface to inform users of a successful
(for example, multiple lines of chat history, including the user’s own messages) reply. When working with this new notification, use the context that gets
so that the user can respond appropriately. passed to the receiver's {@code onReceive()} method.
When the user responds via {@link android.support.v4.app.RemoteInput},
include the text in the reply history with the {@code setRemoteInputHistory()}
method.</p>
<pre>
// 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);
</pre>
</li>
</ol>
<p>
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.
</p>
<h2 id="bundle">Bundled Notifications</h2> <h2 id="bundle">Bundled Notifications</h2>
<p>Android N provides developers with a new way to represent <p>Android N provides developers with a new way to represent