diff options
author | Robert Ly <robertly@google.com> | 2014-05-11 11:25:35 -0700 |
---|---|---|
committer | Robert Ly <robertly@google.com> | 2014-05-16 21:10:52 -0700 |
commit | 6cf59a3edb09c2edbf483b3737a02570603ef659 (patch) | |
tree | e44b4b018dcb7311d09b0ab1b0421cc3be1fd604 /docs | |
parent | 8028e4a063b49aadfb08fab012d2388a7466a9a1 (diff) | |
download | frameworks_base-6cf59a3edb09c2edbf483b3737a02570603ef659.zip frameworks_base-6cf59a3edb09c2edbf483b3737a02570603ef659.tar.gz frameworks_base-6cf59a3edb09c2edbf483b3737a02570603ef659.tar.bz2 |
docs: updates for changes to notification APIs
Change-Id: I8a016b0693e928eb864065bea1079be824987340
Diffstat (limited to 'docs')
-rw-r--r-- | docs/html/wear/notifications/creating.jd | 86 | ||||
-rw-r--r-- | docs/html/wear/notifications/pages.jd | 28 | ||||
-rw-r--r-- | docs/html/wear/notifications/remote-input.jd | 100 | ||||
-rw-r--r-- | docs/html/wear/notifications/stacks.jd | 56 |
4 files changed, 162 insertions, 108 deletions
diff --git a/docs/html/wear/notifications/creating.jd b/docs/html/wear/notifications/creating.jd index ce9e117..a5d7da7 100644 --- a/docs/html/wear/notifications/creating.jd +++ b/docs/html/wear/notifications/creating.jd @@ -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> <pre> -import android.preview.support.wearable.notifications.*; -import android.preview.support.v4.app.NotificationManagerCompat; +import android.support.wearable.notifications.*; +import android.support.wearable.app.NotificationManagerCompat; import android.support.v4.app.NotificationCompat; </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 {@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> @@ -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 for users to deliver your app a text response using voice input.</p> -<p>To use these new APIs, pass your instance of -{@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 -features to your notification using the - <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html" - ><code>WearableNotifications.Builder</code></a> methods. For example:</p> +<p>To use these new APIs:</p> + +<ol> + <li>Create an instance of +{@link android.support.v4.app.NotificationCompat.Builder}, setting the +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> // Create a NotificationCompat.Builder for standard notification features -NotificationCompat.Builder notificationBuilder = - new NotificationCompat.Builder(mContext) - .setContentTitle("New mail from " + sender.toString()) - .setContentText(subject) - .setSmallIcon(R.drawable.new_mail); - -// Create a WearablesNotification.Builder to add special functionality for wearables -Notification notification = - new WearableNotifications.Builder(notificationBuilder) - .setHintHideIcon(true) - .build(); + NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext) + .setContentTitle("New mail from " + sender) + .setContentText(subject) + .setSmallIcon(R.drawable.new_mail); +// Create a WearablesNotificationOptions.Builder to add functionality for wearables + Notification notif = new WearableNotificationOptions.Builder() + <b>.setHintHideIcon(true)</b> + .build() + .applyTo(builder); //apply wearable options to to the original notification + .build() </pre> -<p>The <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#setBigActionIcon(int)"> - <code>setHintHideIcon()</code></a> method removes your app icon from the notification card. - This method is just one example of new notification features available from the - <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html" - ><code>WearableNotifications.Builder</code></a> class.</p> +<p>The + <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#setHintHideIcon(boolean)"> + <code>setHintHideIcon()</code></a> method is just one example of new notification features available with the + <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html" + ><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"> - <code>NotificationManagerCompat</code></a> API:</p> +<p>When you want to deliver your notifications, always use the + <a href="{@docRoot}reference/android/support/wearable/app/NotificationManagerCompat.html"> + <code>NotificationManagerCompat</code></a> API instead of + {@link android.app.NotificationManager}:</p> <pre> // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); -// Build the notification and issues it with notification manager. -notificationManager.notify(notificationId, notification); +// Issue the notification with notification manager. +notificationManager.notify(notificationId, notif); </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> -will not work.</p> + +<p>If you use the framework's {@link android.app.NotificationManager}, some +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 - <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html" - ><code>WearableNotifications.Builder</code></a> and other APIs in the + <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html" + ><code>WearableNotificationOptions.Builder</code></a> and other APIs in the preview support library, see the following developer guides:</p> <dl> diff --git a/docs/html/wear/notifications/pages.jd b/docs/html/wear/notifications/pages.jd index 558f7b8..7d18b3f 100644 --- a/docs/html/wear/notifications/pages.jd +++ b/docs/html/wear/notifications/pages.jd @@ -15,14 +15,19 @@ multiple pages, see the <a href="{@docRoot}wear/design/index.html#NotificationPages">Design Principles of Android Wear</a>.</p> - -<p>When creating a notification with multiple pages, start by creating 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 -<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addPage(android.app.Notification)"> +<p>To create a notification with multiple pages:</p> +<ol> + <li>Create the main notification (the first page) the way you'd like the notification to appear on a phone + or tablet.</li> + <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 -<a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addPages(java.util.Collection<android.app.Notification>)"> -<code>addPages()</code></a> method.</p> +<a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#addPages(java.util.Collection<android.app.Notification>)"> +<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> @@ -47,15 +52,14 @@ Notification secondPageNotification = .setStyle(secondPageStyle) .build(); -// Create main notification and add the second page +// Add second page with wearable options and apply to main notification Notification twoPageNotification = - new WearableNotifications.Builder(notificationBuilder) + new WearableNotificationsOptions.Builder() .addPage(secondPageNotification) + .build() + .applyTo(notificationBuilder) .build(); </pre> - - - </body> </html> diff --git a/docs/html/wear/notifications/remote-input.jd b/docs/html/wear/notifications/remote-input.jd index 1668363..4db8274 100644 --- a/docs/html/wear/notifications/remote-input.jd +++ b/docs/html/wear/notifications/remote-input.jd @@ -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> <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 - <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 - <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 to your app on the handheld.</p> <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 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 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> @@ -73,7 +73,7 @@ RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) </pre> <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> 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 android.support.v4.app.NotificationCompat.Builder#setContentIntent setContentIntent()} 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/preview/support/wearable/notifications/WearableNotifications.Builder.html#addRemoteInputForContentIntent(android.preview.support.wearable.notifications.RemoteInput)"> + <a href="{@docRoot}reference/android/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to the main action using + <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html#addRemoteInputForContentIntent(android.support.wearable.notifications.RemoteInput)"> <code>addRemoteInputForContentIntent()</code></a>. For example:</p> <pre> @@ -116,18 +116,19 @@ RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(replyLabel) .build(); -// Create wearable notification and add remote input +// Add remote input to wearable options and apply to notification Notification replyNotification = - new WearableNotifications.Builder(replyNotificationBuilder) + new WearableNotificationOptions.Builder() .addRemoteInputForContentIntent(remoteInput) + .build() + .applyTo(replyNotificationBuilder) .build(); </pre> - <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 - <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 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 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/preview/support/wearable/notifications/WearableNotifications.Action.html"> + <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/support/wearable/notifications/WearableAction.html"> <code>Action</code></a> object.</p> <p>You should instantiate the - <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> -<code>Action</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.html"> +<code>WearableAction</code></a> with the + <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 {@link android.app.PendingIntent} 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(); // Create the notification action -Action replyAction = new Action.Builder(R.drawable.ic_message, +WearableAction replyAction = new WearableAction.Builder(R.drawable.ic_message, "Reply", pendingIntent) .addRemoteInput(remoteInput) .build(); @@ -169,45 +170,72 @@ Action replyAction = new Action.Builder(R.drawable.ic_message, <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/preview/support/wearable/notifications/WearableNotifications.Action.html"> -<code>Action</code></a>, add the - <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> -<code>Action</code></a> to the - <a href="{@docRoot}reference/android/preview/support/wearable/notifications/WearableNotifications.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/RemoteInput.html"><code>RemoteInput</code></a> to the + <a href="{@docRoot}reference/android/support/wearable/notifications/WearableAction.html"> +<code>Wearablection</code></a>, set the + <a href="{@docRoot}reference/android/support/wearable/notifications/WearableAction.html"> +<code>WearableAction</code></a> on the + <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationOptions.Builder.html"><code>WearableNotifications.Builder</code></a> using + <a href="{@docRoot}reference/android/support/wearable/notifications/WearableNotificationsOptions.Builder.html#addAction(Action)"><code>addAction()</code></a>. For example:</p> <pre> // Create basic notification builder NotificationCompat.Builder replyNotificationBuilder = new NotificationCompat.Builder(this) - .setContentTitle("New message"); + .setContentTitle("New message"); // 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) .addRemoteInput(remoteInput) .build(); // Create wearable notification and add action Notification replyNotification = - new WearableNotifications.Builder(replyNotificationBuilder) - .addAction(replyAction) - .build(); + new WearableNotificationOptions.Builder() + .addAction(replyAction) + .build() + .applyTo(replyNotificationBuilder) + .build(); </pre> + <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). Once the user completes a response, the system invokes the {@link android.content.Intent} attached to the action and adds the <code>EXTRA_VOICE_REPLY</code> extra (the string you passed to the - <a href="{@docRoot}reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> constructor) - with the user's message as the string value.</p> - - - + <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> + +<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> </html> diff --git a/docs/html/wear/notifications/stacks.jd b/docs/html/wear/notifications/stacks.jd index a2d34ce..3c3dc09 100644 --- a/docs/html/wear/notifications/stacks.jd +++ b/docs/html/wear/notifications/stacks.jd @@ -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 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 -<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 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> <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 -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"> 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) .setContentTitle("New mail from " + sender1) .setContentText(subject1) .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) + .build() + .applyTo(builder) .build(); // Issue the notification @@ -52,8 +55,10 @@ notificationManager.notify(notificationId1, notif); </pre> <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 -in the same stack as the previous notification, instead of as a new card:</p> +the same group key. When you call +<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"> builder = new NotificationCompat.Builder(mContext) @@ -62,8 +67,10 @@ builder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.new_mail); // Use the same group as the previous notification -Notification notif2 = new WearableNotifications.Builder(builder) +Notification notif2 = new WearableNotificationOptions.Builder() .setGroup(GROUP_KEY_EMAILS) + .build() + .applyTo(builder) .build(); 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 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 -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> @@ -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. 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 -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 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(), R.drawable.ic_large_icon); +// Create an InboxStyle notification builder = new NotificationCompat.Builder(this) + .setContentTitle("2 new messages") .setSmallIcon(R.drawable.ic_small_icon) - .setLargeIcon(largeIcon); - -// Use the same group key and pass this builder to InboxStyle notification -WearableNotifications.Builder wearableBuilder = new WearableNotifications - .Builder(builder) - .setGroup(GROUP_KEY_EMAILS, - WearableNotifications.GROUP_ORDER_SUMMARY); - -// 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") + .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")); + +// Specify the notification to be the group summary +Notification summaryNotification = new WearableNotificationOptions.Builder() + .setGroupSummary(GROUP_KEY_EMAILS) + .build() + .applyTo(builder) .build(); notificationManager.notify(notificationId3, summaryNotification); |