From 6cf59a3edb09c2edbf483b3737a02570603ef659 Mon Sep 17 00:00:00 2001
From: Robert Ly
-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;@@ -64,7 +64,7 @@ such as action buttons and large icons, while remaining compatible with Android
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
-
+
NotificationManagerCompat
API:
To use these new APIs, pass your instance of
-{@link android.support.v4.app.NotificationCompat.Builder} to the
- WearableNotifications.Builder()
constructor. You can then add new
-features to your notification using the
- WearableNotifications.Builder
methods. For example:
To use these new APIs:
+ +WearableNotificationOptions.Builder
, setting the wearable-specific options for the notication.WearableNotificationOptions.Builder.applyTo()
+ , passing in the {@link android.support.v4.app.NotificationCompat.Builder}. This applies
+ the wearable options to the notification.
+For example, the following code calls the
+
+ setHintHideIcon()
method to remove the app icon from the notification card.
+
// 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() + .setHintHideIcon(true) + .build() + .applyTo(builder); //apply wearable options to to the original notification + .build()-
The
- setHintHideIcon()
method removes your app icon from the notification card.
- This method is just one example of new notification features available from the
- WearableNotifications.Builder
class.
The
+
+ setHintHideIcon()
method is just one example of new notification features available with the
+ WearableNotificationOptions.Builder
class.
+
When you want to deliver your notifications, be certain to always use the
-
- NotificationManagerCompat
API:
When you want to deliver your notifications, always use the
+
+ NotificationManagerCompat
API instead of
+ {@link android.app.NotificationManager}:
// 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);-
If you instead use the framework's {@link android.app.NotificationManager}, some
-features from WearableNotifications.Builder
-will not work.
If you use the framework's {@link android.app.NotificationManager}, some
+features from WearableNotificationOptions.Builder
+do not work.
To continue enhancing your notifications for wearables using
- WearableNotifications.Builder
and other APIs in the
+ WearableNotificationOptions.Builder
and other APIs in the
preview support library, see the following developer guides:
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
-
+ To create a notification with multiple pages:
+
addPage()
method, or add multiple pages in a {@link java.util.Collection} with the
-
-addPages()
method.
addPages()
method.
+ applyTo()
method.For example, here's some code that adds a second page to a notification:
@@ -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(); - - -