public final class

WearableNotifications

extends Object
java.lang.Object
   ↳ android.preview.support.wearable.notifications.WearableNotifications

Class Overview

Helper class that contains wearable extensions for notifications. Always use the WearableNotifications.Builder to create instances of this class.

See Creating Notifications for Android Wear for more information on how to use this class.

To create a notification with wearable extensions:

  1. Create a NotificationCompat.Builder, setting any desired properties.
  2. Create a WearableNotifications.Builder, passing in the NotificationCompat.Builder as a starting point.
  3. Set wearable-specific properties using the add and set methods of WearableNotifications.Builder.
  4. Call build() to create the notification.
  5. Post the notification to the notification system with the NotificationManagerCompat.notify(...) methods and not the NotificationManager.notify(...) methods.
 NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
         .setContentTitle("New mail from " + sender.toString())
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_mail);
 Notification notif = new WearableNotifications.Builder(builder)
         .setLocalOnly(true)
         .setMinPriority()
         .build();
 NotificationManagerCompat.from(mContext).notify(0, notif);

When you receive a notification object from the builder, the methods in this class let you access the values of various notification fields in a backward-compatible manner.

Summary

Nested Classes
class WearableNotifications.Action Subclass of NotificationCompat.Action that adds additional wearable extensions for actions. 
class WearableNotifications.Builder Builder class that wraps a NotificationCompat.Builder to add wearable extensions for a notification. 
Constants
int GROUP_ORDER_DEFAULT Default value for the group sort order.
int GROUP_ORDER_SUMMARY Sentinel value provided to the groupOrder parameter of the setGroup(android.app.Notification, java.lang.String, int) method.
Public Methods
static WearableNotifications.Action getAction(Notification notif, int actionIndex)
Get a WearableNotifications.Action wrapper for the notification at actionIndex in the actions array.
static int getActionCount(Notification notif)
Get the number of actions present on this notification.
static int getBigActionIcon(Notification notif)
Get the big action icon to be displayed with this notification.
static CharSequence getBigActionSubtext(Notification notif)
Get the big action icon subtext to be shown with a big action icon.
static RemoteInput[] getContentIntentRemoteInputs(Notification notif)
Gets the RemoteInput objects associated with the content intent.
static Bundle getExtras(Notification notif)
Gets the extras field from a notification in a backward-compatible manner.
static String getGroupKey(Notification notif)
Get the key used to group this notification into a cluster or stack with other notifications.
static int getGroupOrder(Notification notif)
Get the sort order of this notification within a group of notifications with the same group key set.
static boolean getHintHideIcon(Notification notif)
Get a hint that this notification's icon should not be displayed.
static boolean getLocalOnly(Notification notif)
Get whether or not this notification is only relevant to the current device.
static Notification[] getPages(Notification notif)
Get the array of additional pages of content for displaying this notification.
static void setBigActionIcon(Notification notif, int icon)
Add a big action display to this notification.
static void setBigActionIcon(Notification notif, int icon, CharSequence subtext)
Add a big action display to this notification.
static void setContentIntentRemoteInputs(Notification notif, RemoteInput[] inputs)
Sets RemoteInputs to be collected when the user triggers the contentIntent.
static void setGroup(Notification notif, String groupKey)
Set this notification to be part of a group of notifications sharing the same key.
static void setGroup(Notification notif, String groupKey, int groupOrder)
Set this notification to be part of a group of notifications sharing the same key.
static void setHintHideIcon(Notification notif, boolean hintHideIcon)
Set a hint that this notification's icon should not be displayed.
static void setLocalOnly(Notification notif, boolean localOnly)
Set whether or not this notification is only relevant to the current device.
static void setMinPriority(Notification notif)
Set the priority of this notification to be minimum priority level (PRIORITY_MIN).
static void setPages(Notification notif, Notification[] pages)
Set additional pages of content to display with this notification.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int GROUP_ORDER_DEFAULT

Default value for the group sort order.

Constant Value: 0 (0x00000000)

public static final int GROUP_ORDER_SUMMARY

Sentinel value provided to the groupOrder parameter of the setGroup(android.app.Notification, java.lang.String, int) method. This value indicates that this index of the notification group is the summary of the group.

Constant Value: -1 (0xffffffff)

Public Methods

public static WearableNotifications.Action getAction (Notification notif, int actionIndex)

Get a WearableNotifications.Action wrapper for the notification at actionIndex in the actions array.

Parameters
notif the notification to inspect
actionIndex the index of the desired action

public static int getActionCount (Notification notif)

Get the number of actions present on this notification.

Parameters
notif the notification to inspect
Returns
  • the number of actions for this notification
See Also

public static int getBigActionIcon (Notification notif)

Get the big action icon to be displayed with this notification. Big actions show a hint to users about the action taken when the content intent is triggered.

Parameters
notif the notification to inspect
Returns
  • the icon or 0 if it wasn't set

public static CharSequence getBigActionSubtext (Notification notif)

Get the big action icon subtext to be shown with a big action icon.

Parameters
notif the notification to inspect
Returns
  • the subtext of the big action icon or null if it wasn't exist.

public static RemoteInput[] getContentIntentRemoteInputs (Notification notif)

Gets the RemoteInput objects associated with the content intent.

Parameters
notif the notification to inspect
Returns
  • array of RemoteInput objects or null if it doesn't exist

public static Bundle getExtras (Notification notif)

Gets the extras field from a notification in a backward-compatible manner. Extras field was supported from JellyBean (API level 16) forwards. This function will return null on older API levels.

Parameters
notif the notification to inspect
Returns
  • the extras associated with this notification.

public static String getGroupKey (Notification notif)

Get the key used to group this notification into a cluster or stack with other notifications. This key is unique within a package.

Parameters
notif the notification to inspect

public static int getGroupOrder (Notification notif)

Get the sort order of this notification within a group of notifications with the same group key set. Group orders are 0-indexed integers that are used to sort notifications in ascending order. Can also be the sentinel value GROUP_ORDER_SUMMARY if this is the summary notification for a group.

Parameters
notif the notification to inspect
Returns
  • the sort order of this notification within this group

public static boolean getHintHideIcon (Notification notif)

Get a hint that this notification's icon should not be displayed.

Parameters
notif the notification to inspect
Returns
  • true if this icon should not be displayed, false otherwise. The default value is false if this was never set.

public static boolean getLocalOnly (Notification notif)

Get whether or not this notification is only relevant to the current device.

Some notifications can be bridged to other devices for remote display. If this hint is set, it is recommended that this notification not be bridged.

Parameters
notif the notification to inspect
Returns
  • true if this notification is local only, false otherwise. Default value is false if not set.

public static Notification[] getPages (Notification notif)

Get the array of additional pages of content for displaying this notification. The current notification forms the first page, and elements within this array form subsequent pages. This field can be used to separate a notification into multiple sections.

Parameters
notif the notification to inspect
Returns
  • the pages for this notification

public static void setBigActionIcon (Notification notif, int icon)

Add a big action display to this notification. Big actions show a hint to users about the action taken when the content intent is triggered.

Parameters
notif the notification to modify
icon icon to display for the content action.

public static void setBigActionIcon (Notification notif, int icon, CharSequence subtext)

Add a big action display to this notification. Big actions show a hint to users about the action taken when the content intent is triggered.

Parameters
notif the notification to modify
icon icon to display for the content action.
subtext Optional subtext to display with the big action icon.

public static void setContentIntentRemoteInputs (Notification notif, RemoteInput[] inputs)

Sets RemoteInputs to be collected when the user triggers the contentIntent. These function just as if they were attached to an WearableNotifications.Action.

Parameters
notif the notification to modify
inputs array of RemoteInput objects desired from the user.

public static void setGroup (Notification notif, String groupKey)

Set this notification to be part of a group of notifications sharing the same key. Grouped notifications may display in a cluster or stack on devices which support such rendering. Use the default ordering within a group.

Parameters
notif the notification to modify
groupKey The group key of the group. Unique within a package.

public static void setGroup (Notification notif, String groupKey, int groupOrder)

Set this notification to be part of a group of notifications sharing the same key. Grouped notifications may display in a cluster or stack on devices which support such rendering.

Parameters
notif the notification to modify
groupKey The group key of the group. Unique within a package.
groupOrder The 0-indexed sort order within the group. Can also be set to the sentinel value GROUP_ORDER_SUMMARY to mark this notification as being the group summary.

public static void setHintHideIcon (Notification notif, boolean hintHideIcon)

Set a hint that this notification's icon should not be displayed.

Parameters
notif the notification to modify
hintHideIcon true to hide this icon, false otherwise.

public static void setLocalOnly (Notification notif, boolean localOnly)

Set whether or not this notification is only relevant to the current device.

Some notifications can be bridged to other devices for remote display. This hint can be set to recommend this notification not be bridged.

Parameters
notif the notification to modify
localOnly set to true to keep the notification on this device only, false otherwise.

public static void setMinPriority (Notification notif)

Set the priority of this notification to be minimum priority level (PRIORITY_MIN). When set via WearableNotifications, these minimum priority notifications will bypass the notification manager on platforms that do not support ambient level notifications.

Parameters
notif the notification to modify

public static void setPages (Notification notif, Notification[] pages)

Set additional pages of content to display with this notification. The current notification forms the first page, and pages set using this function form subsequent pages. This field can be used to separate a notification into multiple sections.

Parameters
notif the notification to modify
pages the pages to add to the current notification. Replaces any existing pages with this value.