public static final class

WearableNotifications.Builder

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

Class Overview

Builder class that wraps a NotificationCompat.Builder to add wearable extensions for a notification.

You can chain the "set" methods for this builder in any order, but you must call the build() method last to build the final notification.

Summary

Public Constructors
WearableNotifications.Builder(Context context)
Construct a builder to be used for adding wearable extensions to notifications.
WearableNotifications.Builder(NotificationCompat.Builder builder)
Construct a builder to be used for adding wearable extensions to notifications to a NotificationCompat.Builder.
Public Methods
WearableNotifications.Builder addAction(WearableNotifications.Action action)
Add an action to this notification.
WearableNotifications.Builder addPage(Notification page)
Add an additional page of content to display with this notification.
WearableNotifications.Builder addPages(Collection<Notification> pages)
Add additional pages of content to display with this notification.
WearableNotifications.Builder addRemoteInputForContentIntent(RemoteInput input)
Adds a RemoteInput for the content intent.
Notification build()
Combine all of the options that have been set by both this builder and the wrapped NotificationCompat.Builder object and return a new Notification object.
NotificationCompat.Builder getCompatBuilder()
Return the NotificationCompat.Builder being wrapped by this object.
Bundle getExtras()
Get the current metadata Bundle used by this Builder, creating a new one as necessary.
WearableNotifications.Builder setBigActionIcon(int icon, CharSequence subtext)
Add a big action display to this notification.
WearableNotifications.Builder setBigActionIcon(int icon)
Add a big action display to this notification.
WearableNotifications.Builder setGroup(String groupKey, int groupOrder)
Set this notification to be part of a group of notifications sharing the same key.
WearableNotifications.Builder setGroup(String groupKey)
Set this notification to be part of a group of notifications sharing the same key.
WearableNotifications.Builder setHintHideIcon(boolean hintHideIcon)
Set a hint that this notification's icon should not be displayed.
WearableNotifications.Builder setLocalOnly(boolean localOnly)
Set whether or not this notification is only relevant to the current device.
WearableNotifications.Builder setMinPriority()
Set the priority of this notification to be minimum priority level (PRIORITY_MIN).
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public WearableNotifications.Builder (Context context)

Construct a builder to be used for adding wearable extensions to notifications. Both the wrapped builder (accessible via getCompatBuilder()) and this builder can be used simultaneously, but the build() method from this object must be called in the end.

Always post notifications to the notification system with the NotificationManagerCompat.notify(...) methods instead of the NotificationManager.notify(...) methods.

 WearableNotifications.Builder builder = new WearableNotifications.Builder(mContext)
         .setLocalOnly(true);
 builder.getCompatBuilder()
         .setContentTitle("New mail from " + sender.toString())
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_mail);
 Notification notif = builder.build();
 NotificationManagerCompat.from(mContext).notify(0, notif);

public WearableNotifications.Builder (NotificationCompat.Builder builder)

Construct a builder to be used for adding wearable extensions to notifications to a NotificationCompat.Builder. Both the wrapped builder and this builder can be used simultaneously, but the build() method from this object must be called in the end.

Always post notifications to the notification system with the NotificationManagerCompat.notify(...) methods instead of 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)
         .build();
 NotificationManagerCompat.from(mContext).notify(0, notif);

Public Methods

public WearableNotifications.Builder addAction (WearableNotifications.Action action)

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content. This method accepts WearableNotifications.Action extension wrappers. Actions added by this function are appended when build() is called.

Parameters
action the action to add to this notification
Returns
  • this object for method chaining

public WearableNotifications.Builder addPage (Notification page)

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

Parameters
page the notification to add as another page
Returns
  • this object for method chaining

public WearableNotifications.Builder addPages (Collection<Notification> pages)

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

Parameters
pages a collection of notifications
Returns
  • this object for method chaining

public WearableNotifications.Builder addRemoteInputForContentIntent (RemoteInput input)

Adds a RemoteInput for the content intent. The collected data will be overlayed onto the content intent.

Parameters
input a RemoteInput object to obtain a user response
Returns
  • this object for method chaining

public Notification build ()

Combine all of the options that have been set by both this builder and the wrapped NotificationCompat.Builder object and return a new Notification object.

Returns
  • the notification

public NotificationCompat.Builder getCompatBuilder ()

Return the NotificationCompat.Builder being wrapped by this object.

Returns

public Bundle getExtras ()

Get the current metadata Bundle used by this Builder, creating a new one as necessary.

The returned Bundle is shared with this Builder.

Returns
  • the extras bundle

public WearableNotifications.Builder setBigActionIcon (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
icon icon to display for the content action.
subtext Optional subtext to display with the big action icon.
Returns
  • this object for method chaining

public WearableNotifications.Builder setBigActionIcon (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
icon icon to display for the content action.
Returns
  • this object for method chaining

public WearableNotifications.Builder setGroup (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
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.
Returns
  • this object for method chaining

public WearableNotifications.Builder setGroup (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
groupKey The group key of the group. Unique within a package.
Returns
  • this object for method chaining

public WearableNotifications.Builder setHintHideIcon (boolean hintHideIcon)

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

Parameters
hintHideIcon true to hide the icon, false otherwise.
Returns
  • this object for method chaining

public WearableNotifications.Builder setLocalOnly (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
localOnly true to keep the notification on this device, false otherwise. Default value is false.
Returns
  • this object for method chaining

public WearableNotifications.Builder setMinPriority ()

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.

Returns
  • this object for method chaining