Merge "docs: updates for changes to notification APIs" into klp-modular-dev

This commit is contained in:
Robert Ly
2014-05-19 17:56:18 +00:00
committed by Android (Google) Code Review
4 changed files with 160 additions and 106 deletions

View File

@@ -44,8 +44,8 @@ library</a> and the Developer Preview support library. So to get started,
you should include the following imports in your project code:</p> you should include the following imports in your project code:</p>
<pre> <pre>
import android.preview.support.wearable.notifications.*; import android.support.wearable.notifications.*;
import android.preview.support.v4.app.NotificationManagerCompat; import android.support.wearable.app.NotificationManagerCompat;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
</pre> </pre>
@@ -64,7 +64,7 @@ such as action buttons and large icons, while remaining compatible with Android
<p>For example, here's some code that creates and issues a notification using the <p>For example, here's some code that creates and issues a notification using the
{@link android.support.v4.app.NotificationCompat} APIs combined with the new {@link android.support.v4.app.NotificationCompat} APIs combined with the new
<a href="{@docRoot}reference/android/preview/support/v4/app/NotificationManagerCompat.html"> <a href="{@docRoot}reference/android/support/wearable/app/NotificationManagerCompat.html">
<code>NotificationManagerCompat</code></a> API:</p> <code>NotificationManagerCompat</code></a> API:</p>
@@ -206,54 +206,70 @@ Wear</a>.</p>
you can add additional pages of content that users can view by swiping to the left, or add the ability you can add additional pages of content that users can view by swiping to the left, or add the ability
for users to deliver your app a text response using voice input.</p> for users to deliver your app a text response using voice input.</p>
<p>To use these new APIs, pass your instance of <p>To use these new APIs:</p>
{@link android.support.v4.app.NotificationCompat.Builder} to the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#WearableNotifications.Builder(android.content.Context)"> <code>WearableNotifications.Builder()</code></a> constructor. You can then add new <ol>
features to your notification using the <li>Create an instance of
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html" {@link android.support.v4.app.NotificationCompat.Builder}, setting the
><code>WearableNotifications.Builder</code></a> methods. For example:</p> desired properties for your notification.</li>
<li>Create a
<a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#WearableNotificationOptions.Builder(android.content.Context)"> <code>WearableNotificationOptions.Builder</code></a>, setting the wearable-specific options for the notication.</li>
<li>Call <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#WearableNotificationOptions.Builder#applyTo"><code>WearableNotificationOptions.Builder.applyTo()</code>
</a>, passing in the {@link android.support.v4.app.NotificationCompat.Builder}. This applies
the wearable options to the notification.</li>
</ol>
<p>
For example, the following code calls the
<a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#setHintHideIcon(boolean)">
<code>setHintHideIcon()</code></a> method to remove the app icon from the notification card.
</p>
<pre> <pre>
// Create a NotificationCompat.Builder for standard notification features // Create a NotificationCompat.Builder for standard notification features
NotificationCompat.Builder notificationBuilder = NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
new NotificationCompat.Builder(mContext) .setContentTitle("New mail from " + sender)
.setContentTitle("New mail from " + sender.toString()) .setContentText(subject)
.setContentText(subject) .setSmallIcon(R.drawable.new_mail);
.setSmallIcon(R.drawable.new_mail); // Create a WearablesNotificationOptions.Builder to add functionality for wearables
Notification notif = new WearableNotificationOptions.Builder()
// Create a WearablesNotification.Builder to add special functionality for wearables <b>.setHintHideIcon(true)</b>
Notification notification = .build()
new WearableNotifications.Builder(notificationBuilder) .applyTo(builder); //apply wearable options to to the original notification
.setHintHideIcon(true) .build()
.build();
</pre> </pre>
<p>The <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#setBigActionIcon(int)"> <p>The
<code>setHintHideIcon()</code></a> method removes your app icon from the notification card. <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#setHintHideIcon(boolean)">
This method is just one example of new notification features available from the <code>setHintHideIcon()</code></a> method is just one example of new notification features available with the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html" <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html"
><code>WearableNotifications.Builder</code></a> class.</p> ><code>WearableNotificationOptions.Builder</code></a> class.
</p>
<p>When you want to deliver your notifications, be certain to always use the
<a href="{@docRoot}reference/android/preview/support/v4/app/NotificationManagerCompat.html"> <p>When you want to deliver your notifications, always use the
<code>NotificationManagerCompat</code></a> API:</p> <a href="{@docRoot}reference/android/support/wearable/app/NotificationManagerCompat.html">
<code>NotificationManagerCompat</code></a> API instead of
{@link android.app.NotificationManager}:</p>
<pre> <pre>
// Get an instance of the NotificationManager service // Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager = NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this); NotificationManagerCompat.from(this);
// Build the notification and issues it with notification manager. // Issue the notification with notification manager.
notificationManager.notify(notificationId, notification); notificationManager.notify(notificationId, notif);
</pre> </pre>
<p>If you instead use the framework's {@link android.app.NotificationManager}, some
features from <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html"><code>WearableNotifications.Builder</code></a> <p>If you use the framework's {@link android.app.NotificationManager}, some
will not work.</p> features from <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html"><code>WearableNotificationOptions.Builder</code></a>
do not work.</p>
<p>To continue enhancing your notifications for wearables using <p>To continue enhancing your notifications for wearables using
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html" <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html"
><code>WearableNotifications.Builder</code></a> and other APIs in the ><code>WearableNotificationOptions.Builder</code></a> and other APIs in the
preview support library, see the following developer guides:</p> preview support library, see the following developer guides:</p>
<dl> <dl>

View File

@@ -15,14 +15,19 @@ multiple pages, see the
<a href="{@docRoot}wear/design/index.html#NotificationPages">Design Principles of Android <a href="{@docRoot}wear/design/index.html#NotificationPages">Design Principles of Android
Wear</a>.</p> Wear</a>.</p>
<p>To create a notification with multiple pages:</p>
<p>When creating a notification with multiple pages, start by creating the main notification <ol>
(the first page) the way you'd like the notification to appear on a phone <li>Create the main notification (the first page) the way you'd like the notification to appear on a phone
or tablet. Then, add pages one at a time with the or tablet.</li>
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addPage(android.app.Notification)"> <li>Add pages one at a time with the
<a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#addPage(android.app.Notification)">
<code>addPage()</code></a> method, or add multiple pages in a {@link java.util.Collection} with the <code>addPage()</code></a> method, or add multiple pages in a {@link java.util.Collection} with the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addPages(java.util.Collection<android.app.Notification>)"> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#addPages(java.util.Collection<android.app.Notification>)">
<code>addPages()</code></a> method.</p> <code>addPages()</code></a> method.</li>
<li>Apply the pages to the main notification with the
<a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.html#applyTo(android.support.v4.app.NotificationCompat.Builder)"
><code>applyTo()</code></a> method.</li>
</ol>
<p>For example, here's some code that adds a second page to a notification:</p> <p>For example, here's some code that adds a second page to a notification:</p>
@@ -47,15 +52,14 @@ Notification secondPageNotification =
.setStyle(secondPageStyle) .setStyle(secondPageStyle)
.build(); .build();
// Create main notification and add the second page // Add second page with wearable options and apply to main notification
Notification twoPageNotification = Notification twoPageNotification =
new WearableNotifications.Builder(notificationBuilder) new WearableNotificationsOptions.Builder()
.addPage(secondPageNotification) .addPage(secondPageNotification)
.build()
.applyTo(notificationBuilder)
.build(); .build();
</pre> </pre>
</body> </body>
</html> </html>

View File

@@ -25,16 +25,16 @@ you must type text replies into the voice input field, so be sure you have enabl
<h2 id="RemoteInput">Define the Remote Input</h2> <h2 id="RemoteInput">Define the Remote Input</h2>
<p>To create an action that supports voice input, first create an instance of <p>To create an action that supports voice input, first create an instance of
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.html"> <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html">
<code>RemoteInput</code></a> using the <code>RemoteInput</code></a> using the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> APIs. <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> APIs.
The The
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> constructor takes a string that the system <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> constructor takes a string that the system
will use as a key for the {@link android.content.Intent} extra that carries the reply message will use as a key for the {@link android.content.Intent} extra that carries the reply message
to your app on the handheld.</p> to your app on the handheld.</p>
<p>For example, here's how to create a new <p>For example, here's how to create a new
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.html"> <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html">
<code>RemoteInput</code></a> object that provides a custom <code>RemoteInput</code></a> object that provides a custom
label for the voice input prompt:</p> label for the voice input prompt:</p>
@@ -56,7 +56,7 @@ RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
<p>In addition to allowing voice input, you can <p>In addition to allowing voice input, you can
provide up to five text responses that the user can select for quick replies. Call provide up to five text responses that the user can select for quick replies. Call
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html#setChoices(java.lang.String[])"><code>setChoices()</code></a> and pass it a string array.</p> <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.Builder.html#setChoices(java.lang.String[])"><code>setChoices()</code></a> and pass it a string array.</p>
<p>For example, you may define some responses in a resource array:</p> <p>For example, you may define some responses in a resource array:</p>
@@ -73,7 +73,7 @@ RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
</pre> </pre>
<p>Then, inflate the string array and add it to the <p>Then, inflate the string array and add it to the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a>:</p> <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a>:</p>
<pre> <pre>
String replyLabel = getResources().getString(R.string.reply_label); String replyLabel = getResources().getString(R.string.reply_label);
@@ -93,8 +93,8 @@ RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
<p>If "Reply" is your notification's primary action (defined by the {@link <p>If "Reply" is your notification's primary action (defined by the {@link
android.support.v4.app.NotificationCompat.Builder#setContentIntent setContentIntent()} android.support.v4.app.NotificationCompat.Builder#setContentIntent setContentIntent()}
method), then you should attach the method), then you should attach the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to the main action using <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to the main action using
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addRemoteInputForContentIntent(android.preview.support.wearable.notifications.RemoteInput)"> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#addRemoteInputForContentIntent(android.support.wearable.notifications.RemoteInput)">
<code>addRemoteInputForContentIntent()</code></a>. For example:</p> <code>addRemoteInputForContentIntent()</code></a>. For example:</p>
<pre> <pre>
@@ -116,18 +116,19 @@ RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.setLabel(replyLabel) .setLabel(replyLabel)
.build(); .build();
// Create wearable notification and add remote input // Add remote input to wearable options and apply to notification
Notification replyNotification = Notification replyNotification =
new WearableNotifications.Builder(replyNotificationBuilder) new WearableNotificationOptions.Builder()
.addRemoteInputForContentIntent(remoteInput) .addRemoteInputForContentIntent(remoteInput)
.build()
.applyTo(replyNotificationBuilder)
.build(); .build();
</pre> </pre>
<p>By using <p>By using
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addRemoteInputForContentIntent(android.preview.support.wearable.notifications.RemoteInput)"> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#addRemoteInputForContentIntent(android.support.wearable.notifications.RemoteInput)">
<code>addRemoteInputForContentIntent()</code></a> to add the <code>addRemoteInputForContentIntent()</code></a> to add the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> object to the notification's primary action, <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> object to the notification's primary action,
the button that normally appears as an "Open" action becomes the "Reply" action the button that normally appears as an "Open" action becomes the "Reply" action
and starts the voice input UI when users select it on Android Wear.</p> and starts the voice input UI when users select it on Android Wear.</p>
@@ -137,14 +138,14 @@ and starts the voice input UI when users select it on Android Wear.</p>
<p>If the "Reply" action is not your notification's primary action and you want to enable <p>If the "Reply" action is not your notification's primary action and you want to enable
voice input for a secondary action, add the voice input for a secondary action, add the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to a new action button defined by an <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to a new action button defined by an
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableAction.html">
<code>Action</code></a> object.</p> <code>Action</code></a> object.</p>
<p>You should instantiate the <p>You should instantiate the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableAction.html">
<code>Action</code></a> with the <code>WearableAction</code></a> with the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Action.Builder.html"><code>Action.Builder()</code></a> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableAction.Builder.html"><code>WearableAction.Builder()</code></a>
constructor, which takes an icon and text label for the action button, plus the constructor, which takes an icon and text label for the action button, plus the
{@link android.app.PendingIntent} {@link android.app.PendingIntent}
the system should use to invoke your app when the user selects the action. For example:</p> the system should use to invoke your app when the user selects the action. For example:</p>
@@ -161,7 +162,7 @@ RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.build(); .build();
// Create the notification action // Create the notification action
Action replyAction = new Action.Builder(R.drawable.ic_message, WearableAction replyAction = new WearableAction.Builder(R.drawable.ic_message,
"Reply", pendingIntent) "Reply", pendingIntent)
.addRemoteInput(remoteInput) .addRemoteInput(remoteInput)
.build(); .build();
@@ -169,45 +170,72 @@ Action replyAction = new Action.Builder(R.drawable.ic_message,
<p>After you add the <p>After you add the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to the <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableAction.html">
<code>Action</code></a>, add the <code>Wearablection</code></a>, set the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableAction.html">
<code>Action</code></a> to the <code>WearableAction</code></a> on the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html"><code>WearableNotifications.Builder</code></a> using <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html"><code>WearableNotifications.Builder</code></a> using
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addAction(Action)"><code>addAction()</code></a>. <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationsOptions.Builder.html#addAction(Action)"><code>addAction()</code></a>.
For example:</p> For example:</p>
<pre> <pre>
// Create basic notification builder // Create basic notification builder
NotificationCompat.Builder replyNotificationBuilder = NotificationCompat.Builder replyNotificationBuilder =
new NotificationCompat.Builder(this) new NotificationCompat.Builder(this)
.setContentTitle("New message"); .setContentTitle("New message");
// Create the notification action and add remote input // Create the notification action and add remote input
Action replyAction = new Action.Builder(R.drawable.ic_message, WearableAction replyAction = new WearableAction.Builder(R.drawable.ic_message,
"Reply", pendingIntent) "Reply", pendingIntent)
.addRemoteInput(remoteInput) .addRemoteInput(remoteInput)
.build(); .build();
// Create wearable notification and add action // Create wearable notification and add action
Notification replyNotification = Notification replyNotification =
new WearableNotifications.Builder(replyNotificationBuilder) new WearableNotificationOptions.Builder()
.addAction(replyAction) .addAction(replyAction)
.build(); .build()
.applyTo(replyNotificationBuilder)
.build();
</pre> </pre>
<p>Now, when the user selects "Reply" from an Android wearable, the system prompts the user <p>Now, when the user selects "Reply" from an Android wearable, the system prompts the user
for voice input (and shows the list of pre-defined replies, if provided). for voice input (and shows the list of pre-defined replies, if provided).
Once the user completes a response, the system invokes Once the user completes a response, the system invokes
the {@link android.content.Intent} attached to the action and adds the the {@link android.content.Intent} attached to the action and adds the
<code>EXTRA_VOICE_REPLY</code> extra (the string <code>EXTRA_VOICE_REPLY</code> extra (the string
you passed to the you passed to the
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> constructor) <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> constructor)
with the user's message as the string value.</p> with the user's message as the string value.</p>
<h2 id="ObtainInput">Obtaining the Voice Input as a String</h2>
<p>To obtain the user's voice input, call
<a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html#getResultsFromIntent(Intent)"><code>getResultsFromIntent()</code></a>,
passing in the "Reply" action's intent. This method returns
a {@link android.os.Bundle} that represents the intent's extras. You can then query the
{@link android.os.Bundle} to obtain the user's voice input string.
</p>
<p>
The following code shows a method that accepts an intent and returns the voice input string,
which is referenced by the <code>EXTRA_VOICE_REPLY</code> key that is used in the previous examples:
</p>
<pre>
/**
* Obtain the intent that started this activity by calling
* Activity.getIntent() and pass it into this method to
* get the associated voice input string.
*/
private String getMessageText(Intent intent) {
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput != null) {
return remoteInput.getString(Intent.EXTRA_VOICE_REPLY);
}
}
return null;
}
</pre>
</body> </body>
</html> </html>

View File

@@ -16,7 +16,7 @@ are not able to read details from each message on the wearable (they must open y
handheld to view more information). So for the wearable device, you should handheld to view more information). So for the wearable device, you should
group all the notifications together in a stack. The stack of notifications appears as a single group all the notifications together in a stack. The stack of notifications appears as a single
card, which users can expand to view the details from each notification separately. The new card, which users can expand to view the details from each notification separately. The new
<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#setGroup(java.lang.String, int)"> <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#setGroup(java.lang.String, int)">
<code>setGroup()</code></a> method makes this possible while allowing you to still provide <code>setGroup()</code></a> method makes this possible while allowing you to still provide
only one summary notification on the handheld device.</p> only one summary notification on the handheld device.</p>
@@ -28,21 +28,24 @@ Wear</a>.</p>
<h2 id="AddGroup">Add Each Notification to a Group</h2> <h2 id="AddGroup">Add Each Notification to a Group</h2>
<p>To create a stack, call <a <p>To create a stack, call <a
href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#setGroup(java.lang.String, int)"> href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#setGroup(java.lang.String, int)">
<code>setGroup()</code></a> for each notification you want in the stack and specify a <code>setGroup()</code></a> for each notification you want in the stack and specify a
group key. Then call <a href="{@docRoot}reference/android/preview/support/v4/app/NotificationManagerCompat.html#notify(int, android.app.Notification)"><code>notify()</code></a> to send it to the wearable.</p> group key. Then call <a href="{@docRoot}reference/android/support/wearable/app/NotificationManagerCompat.html#notify(int, android.app.Notification)"><code>notify()</code></a> to send it to the wearable.</p>
<pre style="clear:right"> <pre style="clear:right">
final static String GROUP_KEY_EMAILS = "group_key_emails"; final static String GROUP_KEY_EMAILS = "group_key_emails";
// Build the notification and pass this builder to WearableNotifications.Builder // Build the notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext) NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
.setContentTitle("New mail from " + sender1) .setContentTitle("New mail from " + sender1)
.setContentText(subject1) .setContentText(subject1)
.setSmallIcon(R.drawable.new_mail); .setSmallIcon(R.drawable.new_mail);
Notification notif1 = new WearableNotifications.Builder(builder) // Set the group with WearableNotificationOptions.Builder and apply to the notification
Notification notif1 = new WearableNotificationOptions.Builder()
.setGroup(GROUP_KEY_EMAILS) .setGroup(GROUP_KEY_EMAILS)
.build()
.applyTo(builder)
.build(); .build();
// Issue the notification // Issue the notification
@@ -52,8 +55,10 @@ notificationManager.notify(notificationId1, notif);
</pre> </pre>
<p>Later on, when you create another notification, specify <p>Later on, when you create another notification, specify
the same group key. When you call <a href="{@docRoot}reference/android/preview/support/v4/app/NotificationManagerCompat.html#notify(int, android.app.Notification)"><code>notify()</code></a>, this notification appears the same group key. When you call
in the same stack as the previous notification, instead of as a new card:</p> <a href="{@docRoot}reference/android/support/v4/app/NotificationManagerCompat.html#notify(int, android.app.Notification)"><code>notify()</code></a>,
this notification appears in the same stack as the previous notification,
instead of as a new card:</p>
<pre style="clear:right"> <pre style="clear:right">
builder = new NotificationCompat.Builder(mContext) builder = new NotificationCompat.Builder(mContext)
@@ -62,8 +67,10 @@ builder = new NotificationCompat.Builder(mContext)
.setSmallIcon(R.drawable.new_mail); .setSmallIcon(R.drawable.new_mail);
// Use the same group as the previous notification // Use the same group as the previous notification
Notification notif2 = new WearableNotifications.Builder(builder) Notification notif2 = new WearableNotificationOptions.Builder()
.setGroup(GROUP_KEY_EMAILS) .setGroup(GROUP_KEY_EMAILS)
.build()
.applyTo(builder)
.build(); .build();
notificationManager.notify(notificationId2, notif); notificationManager.notify(notificationId2, notif);
@@ -72,7 +79,7 @@ notificationManager.notify(notificationId2, notif);
<p>By default, notifications appear in the order in which you added them, with the most recent <p>By default, notifications appear in the order in which you added them, with the most recent
notification visible at the top. You can define a specific position in the group notification visible at the top. You can define a specific position in the group
by passing an order position as the second parameter for <a by passing an order position as the second parameter for <a
href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#setGroup(java.lang.String, int)"> href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#setGroup(java.lang.String, int)">
<code>setGroup()</code></a>.</p> <code>setGroup()</code></a>.</p>
@@ -83,7 +90,7 @@ href="{@docRoot}reference/android/preview/support/wearable/notifications/Wearabl
<p>It's important that you still provide a summary notification that appears on handheld devices. <p>It's important that you still provide a summary notification that appears on handheld devices.
So in addition to adding each unique notification to the same stack group, also add a summary So in addition to adding each unique notification to the same stack group, also add a summary
notification, but set its order position to be <a notification, but set its order position to be <a
href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.html#GROUP_ORDER_SUMMARY"><code>GROUP_ORDER_SUMMARY</code></a>.</p> href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationsOptions.html#GROUP_ORDER_SUMMARY"><code>GROUP_ORDER_SUMMARY</code></a>.</p>
<p>This notification does not appear in your stack of notifications on the wearable, but <p>This notification does not appear in your stack of notifications on the wearable, but
appears as the only notification on the handheld device.</p> appears as the only notification on the handheld device.</p>
@@ -92,23 +99,22 @@ appears as the only notification on the handheld device.</p>
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_large_icon); R.drawable.ic_large_icon);
// Create an InboxStyle notification
builder = new NotificationCompat.Builder(this) builder = new NotificationCompat.Builder(this)
.setContentTitle("2 new messages")
.setSmallIcon(R.drawable.ic_small_icon) .setSmallIcon(R.drawable.ic_small_icon)
.setLargeIcon(largeIcon); .setLargeIcon(largeIcon)
.setStyle(new NotificationCompat.InboxStyle()
.addLine("Alex Faaborg Check this out")
.addLine("Jeff Chang Launch Party")
.setBigContentTitle("2 new messages")
.setSummaryText("johndoe@gmail.com"));
// Use the same group key and pass this builder to InboxStyle notification // Specify the notification to be the group summary
WearableNotifications.Builder wearableBuilder = new WearableNotifications Notification summaryNotification = new WearableNotificationOptions.Builder()
.Builder(builder) .setGroupSummary(GROUP_KEY_EMAILS)
.setGroup(GROUP_KEY_EMAILS, .build()
WearableNotifications.GROUP_ORDER_SUMMARY); .applyTo(builder)
// Build the final notification to show on the handset
Notification summaryNotification = new NotificationCompat.InboxStyle(
wearableBuilder.getCompatBuilder())
.addLine("Alex Faaborg Check this out")
.addLine("Jeff Chang Launch Party")
.setBigContentTitle("2 new messages")
.setSummaryText("johndoe@gmail.com")
.build(); .build();
notificationManager.notify(notificationId3, summaryNotification); notificationManager.notify(notificationId3, summaryNotification);