Google is committed to advancing racial equity for Black communities. See how.

WearableExtender

class WearableExtender : NotificationCompat.Extender
kotlin.Any
   ↳ androidx.core.app.NotificationCompat.WearableExtender

Helper class to add wearable extensions to notifications.

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 NotificationCompat.WearableExtender.
  3. Set wearable-specific properties using the add and set methods of NotificationCompat.WearableExtender.
  4. Call NotificationCompat.Builder#extend to apply the extensions to a notification.
  5. Post the notification to the notification system with the NotificationManagerCompat.notify(...) methods and not the NotificationManager.notify(...) methods.
Notification notification = new NotificationCompat.Builder(mContext)
              .setContentTitle("New mail from " + sender.toString())
              .setContentText(subject)
              .setSmallIcon(R.drawable.new_mail)
              .extend(new NotificationCompat.WearableExtender()
                      .setContentIcon(R.drawable.new_mail))
              .build();
      NotificationManagerCompat.from(mContext).notify(0, notification);

Wearable extensions can be accessed on an existing notification by using the WearableExtender(Notification) constructor, and then using the get methods to access values.

NotificationCompat.WearableExtender wearableExtender =
              new NotificationCompat.WearableExtender(notification);
      List<Notification> pages = wearableExtender.getPages();

Summary

Constants
static Int

Sentinel value for use with setHintScreenTimeout to keep the screen on for a longer amount of time when this notification is displayed on the screen.

static Int

Sentinel value for use with setHintScreenTimeout to keep the screen on for a short amount of time when this notification is displayed on the screen.

static Int

Size value for use with setCustomSizePreset to show this notification with default sizing.

static Int

Size value for use with setCustomSizePreset to show this notification full screen.

static Int

Size value for use with setCustomSizePreset to show this notification with a large size.

static Int

Size value for use with setCustomSizePreset to show this notification with a medium size.

static Int

Size value for use with setCustomSizePreset to show this notification with a small size.

static Int

Size value for use with setCustomSizePreset to show this notification with an extra small size.

static Int

Sentinel value for an action index that is unset.

Public constructors

Create a NotificationCompat.WearableExtender with default options.

<init>(@NonNull notification: Notification)

Public methods
NotificationCompat.WearableExtender

Add a wearable action to this notification.

NotificationCompat.WearableExtender

Adds wearable actions to this notification.

NotificationCompat.WearableExtender
addPage(@NonNull page: Notification)

Add an additional page of content to display with this notification.

NotificationCompat.WearableExtender
addPages(@NonNull pages: MutableList<Notification!>)

Add additional pages of content to display with this notification.

NotificationCompat.WearableExtender

Clear all wearable actions present on this builder.

NotificationCompat.WearableExtender

Clear all additional pages present on this builder.

NotificationCompat.WearableExtender

NotificationCompat.Builder

Apply wearable extensions to a notification that is being built.

MutableList<NotificationCompat.Action!>

Get the wearable actions present on this notification.

Bitmap?

Get a background image to be displayed behind the notification content.

String?

Returns the bridge tag of the notification.

Int

Get the index of the notification action, if any, that was specified as the primary action.

Int

Get an icon that goes with the content of this notification.

Int

Get the gravity that the content icon should have within the notification display.

Boolean

Get whether the content intent is available when the wearable device is not connected to a companion device.

Int

Get the custom height in pixels for the display of this notification's content.

Int

Get the custom size preset for the display of this notification out of the available presets found in NotificationCompat.WearableExtender, e.

String?

Returns the dismissal id of the notification.

PendingIntent?

Get the intent to launch inside of an activity view when displaying this notification.

Int

Get the gravity that this notification should have within the available viewport space.

Boolean

Get a hint that this notification's BigPictureStyle (if present) should be converted to low-bit and displayed in ambient mode, especially useful for barcodes and qr codes, as well as other simple black-and-white tickets.

Boolean

Get a hint that this notification's background should not be clipped if possible, and should instead be resized to fully display on the screen, retaining the aspect ratio of the image.

Boolean

Get a hint that this notification's content intent will launch an Activity directly, telling the platform that it can generate the appropriate transitions

Boolean

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

Int

Get the duration, in milliseconds, that the screen should remain on for when this notification is displayed.

Boolean

Get a visual hint that only the background image of this notification should be displayed, and other semantic content should be hidden.

MutableList<Notification!>

Get the array of additional pages of content for displaying this notification.

Boolean

Get whether the scrolling position for the contents of this notification should start at the bottom of the contents instead of the top when the contents are too long to display within the screen.

NotificationCompat.WearableExtender
setBackground(@Nullable background: Bitmap?)

Set a background image to be displayed behind the notification content.

NotificationCompat.WearableExtender
setBridgeTag(@Nullable bridgeTag: String?)

Sets a bridge tag for this notification.

NotificationCompat.WearableExtender
setContentAction(actionIndex: Int)

Set an action from this notification's actions as the primary action.

NotificationCompat.WearableExtender

Set an icon that goes with the content of this notification.

NotificationCompat.WearableExtender
setContentIconGravity(contentIconGravity: Int)

Set the gravity that the content icon should have within the notification display.

NotificationCompat.WearableExtender
setContentIntentAvailableOffline(contentIntentAvailableOffline: Boolean)

Set whether the content intent is available when the wearable device is not connected to a companion device.

NotificationCompat.WearableExtender

Set the custom height in pixels for the display of this notification's content.

NotificationCompat.WearableExtender
setCustomSizePreset(sizePreset: Int)

Set the custom size preset for the display of this notification out of the available presets found in NotificationCompat.WearableExtender, e.

NotificationCompat.WearableExtender
setDismissalId(@Nullable dismissalId: String?)

Sets the dismissal id for this notification.

NotificationCompat.WearableExtender
setDisplayIntent(@Nullable intent: PendingIntent?)

Set an intent to launch inside of an activity view when displaying this notification.

NotificationCompat.WearableExtender
setGravity(gravity: Int)

Set the gravity that this notification should have within the available viewport space.

NotificationCompat.WearableExtender
setHintAmbientBigPicture(hintAmbientBigPicture: Boolean)

Set a hint that this notification's BigPictureStyle (if present) should be converted to low-bit and displayed in ambient mode, especially useful for barcodes and qr codes, as well as other simple black-and-white tickets.

NotificationCompat.WearableExtender
setHintAvoidBackgroundClipping(hintAvoidBackgroundClipping: Boolean)

Set a hint that this notification's background should not be clipped if possible, and should instead be resized to fully display on the screen, retaining the aspect ratio of the image.

NotificationCompat.WearableExtender
setHintContentIntentLaunchesActivity(hintContentIntentLaunchesActivity: Boolean)

Set a hint that this notification's content intent will launch an Activity directly, telling the platform that it can generate the appropriate transitions.

NotificationCompat.WearableExtender
setHintHideIcon(hintHideIcon: Boolean)

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

NotificationCompat.WearableExtender

Set a hint that the screen should remain on for at least this duration when this notification is displayed on the screen.

NotificationCompat.WearableExtender
setHintShowBackgroundOnly(hintShowBackgroundOnly: Boolean)

Set a visual hint that only the background image of this notification should be displayed, and other semantic content should be hidden.

NotificationCompat.WearableExtender
setStartScrollBottom(startScrollBottom: Boolean)

Set whether the scrolling position for the contents of this notification should start at the bottom of the contents instead of the top when the contents are too long to display within the screen.

Constants

SCREEN_TIMEOUT_LONG

static val SCREEN_TIMEOUT_LONG: Int

Deprecated: This feature is no longer supported.

Sentinel value for use with setHintScreenTimeout to keep the screen on for a longer amount of time when this notification is displayed on the screen.

Value: -1

SCREEN_TIMEOUT_SHORT

static val SCREEN_TIMEOUT_SHORT: Int

Deprecated: This feature is no longer supported.

Sentinel value for use with setHintScreenTimeout to keep the screen on for a short amount of time when this notification is displayed on the screen. This is the default value.

Value: 0

SIZE_DEFAULT

static val SIZE_DEFAULT: Int

Deprecated: Display intents are no longer supported.

Size value for use with setCustomSizePreset to show this notification with default sizing.

For custom display notifications created using setDisplayIntent, the default is SIZE_MEDIUM. All other notifications size automatically based on their content.

Value: 0

SIZE_FULL_SCREEN

static val SIZE_FULL_SCREEN: Int

Deprecated: Display intents are no longer supported.

Size value for use with setCustomSizePreset to show this notification full screen.

This value is only applicable for custom display notifications created using setDisplayIntent.

Value: 5

SIZE_LARGE

static val SIZE_LARGE: Int

Deprecated: Display intents are no longer supported.

Size value for use with setCustomSizePreset to show this notification with a large size.

This value is only applicable for custom display notifications created using setDisplayIntent.

Value: 4

SIZE_MEDIUM

static val SIZE_MEDIUM: Int

Deprecated: Display intents are no longer supported.

Size value for use with setCustomSizePreset to show this notification with a medium size.

This value is only applicable for custom display notifications created using setDisplayIntent.

Value: 3

SIZE_SMALL

static val SIZE_SMALL: Int

Deprecated: Display intents are no longer supported.

Size value for use with setCustomSizePreset to show this notification with a small size.

This value is only applicable for custom display notifications created using setDisplayIntent.

Value: 2

SIZE_XSMALL

static val SIZE_XSMALL: Int

Deprecated: Display intents are no longer supported.

Size value for use with setCustomSizePreset to show this notification with an extra small size.

This value is only applicable for custom display notifications created using setDisplayIntent.

Value: 1

UNSET_ACTION_INDEX

static val UNSET_ACTION_INDEX: Int

Sentinel value for an action index that is unset.

Value: -1

Public constructors

<init>

WearableExtender()

Create a NotificationCompat.WearableExtender with default options.

<init>

WearableExtender(@NonNull notification: Notification)

Public methods

addAction

@NonNull fun addAction(@NonNull action: NotificationCompat.Action): NotificationCompat.WearableExtender

Add a wearable action to this notification.

When wearable actions are added using this method, the set of actions that show on a wearable device splits from devices that only show actions added using NotificationCompat.Builder#addAction. This allows for customization of which actions display on different devices.

Parameters
action NotificationCompat.Action: the action to add to this notification
Return
NotificationCompat.WearableExtender this object for method chaining

addActions

@NonNull fun addActions(@NonNull actions: MutableList<NotificationCompat.Action!>): NotificationCompat.WearableExtender

Adds wearable actions to this notification.

When wearable actions are added using this method, the set of actions that show on a wearable device splits from devices that only show actions added using NotificationCompat.Builder#addAction. This allows for customization of which actions display on different devices.

Parameters
actions MutableList<NotificationCompat.Action!>: the actions to add to this notification
Return
NotificationCompat.WearableExtender this object for method chaining

addPage

@NonNull fun addPage(@NonNull page: Notification): NotificationCompat.WearableExtender

Deprecated: Multiple content pages are no longer supported.

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 Notification: the notification to add as another page
Return
NotificationCompat.WearableExtender this object for method chaining

addPages

@NonNull fun addPages(@NonNull pages: MutableList<Notification!>): NotificationCompat.WearableExtender

Deprecated: Multiple content pages are no longer supported.

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 MutableList<Notification!>: a list of notifications
Return
NotificationCompat.WearableExtender this object for method chaining

clearActions

@NonNull fun clearActions(): NotificationCompat.WearableExtender

Clear all wearable actions present on this builder.

Return
NotificationCompat.WearableExtender this object for method chaining.

See Also

clearPages

@NonNull fun clearPages(): NotificationCompat.WearableExtender

Deprecated: Multiple content pages are no longer supported.

Clear all additional pages present on this builder.

Return
NotificationCompat.WearableExtender this object for method chaining.

See Also

clone

@NonNull fun clone(): NotificationCompat.WearableExtender

extend

@NonNull fun extend(@NonNull builder: NotificationCompat.Builder): NotificationCompat.Builder

Apply wearable extensions to a notification that is being built. This is typically called by the NotificationCompat.Builder#extend method of NotificationCompat.Builder.

Parameters
builder NotificationCompat.Builder: the builder to be modified.
Return
NotificationCompat.Builder the build object for chaining.

getActions

@NonNull fun getActions(): MutableList<NotificationCompat.Action!>

Get the wearable actions present on this notification.

getBackground

@Nullable fun getBackground(): Bitmap?

Deprecated: Background images are no longer supported.

Get a background image to be displayed behind the notification content. Contrary to the NotificationCompat.BigPictureStyle, this background will work with any notification style.

Return
Bitmap? the background image

getBridgeTag

@Nullable fun getBridgeTag(): String?

Returns the bridge tag of the notification.

Return
String? the bridge tag or null if not present.

getContentAction

fun getContentAction(): Int

Get the index of the notification action, if any, that was specified as the primary action.

If wearable specific actions were added to the main notification, this index will apply to that list, otherwise it will apply to the regular actions list.

Return
Int the action index or UNSET_ACTION_INDEX if no action was selected.

getContentIcon

fun getContentIcon(): Int

Deprecated: This method has no effect starting with Wear 2.0.

Get an icon that goes with the content of this notification.

getContentIconGravity

fun getContentIconGravity(): Int

Deprecated: This method has no effect starting with Wear 2.0.

Get the gravity that the content icon should have within the notification display. Supported values include android.view.Gravity#START and android.view.Gravity#END. The default value is android.view.Gravity#END.

See Also

getContentIntentAvailableOffline

fun getContentIntentAvailableOffline(): Boolean

Get whether the content intent is available when the wearable device is not connected to a companion device. The user can still trigger this intent when the wearable device is offline, but a visual hint will indicate that the content intent may not be available. Defaults to true.

getCustomContentHeight

fun getCustomContentHeight(): Int

Deprecated: This method has no effect starting with Wear 2.0.

Get the custom height in pixels for the display of this notification's content.

This option is only available for custom display notifications created using setDisplayIntent. See also setCustomSizePreset and setCustomContentHeight.

getCustomSizePreset

fun getCustomSizePreset(): Int

Deprecated: This method has no effect starting with Wear 2.0.

Get the custom size preset for the display of this notification out of the available presets found in NotificationCompat.WearableExtender, e.g. SIZE_LARGE.

Some custom size presets are only applicable for custom display notifications created using setDisplayIntent. Check the documentation for the preset in question. See also setCustomContentHeight and setCustomSizePreset.

getDismissalId

@Nullable fun getDismissalId(): String?

Returns the dismissal id of the notification.

Return
String? the dismissal id of the notification or null if it has not been set.

getDisplayIntent

@Nullable fun getDisplayIntent(): PendingIntent?

Deprecated: Display intents are no longer supported.

Get the intent to launch inside of an activity view when displaying this notification. This PendingIntent should be for an activity.

getGravity

fun getGravity(): Int

Deprecated: This method has no effect starting with Wear 2.0.

Get the gravity that this notification should have within the available viewport space. Supported values include android.view.Gravity#TOP, android.view.Gravity#CENTER_VERTICAL and android.view.Gravity#BOTTOM. The default value is android.view.Gravity#BOTTOM.

getHintAmbientBigPicture

fun getHintAmbientBigPicture(): Boolean

Deprecated: This feature is no longer supported.

Get a hint that this notification's BigPictureStyle (if present) should be converted to low-bit and displayed in ambient mode, especially useful for barcodes and qr codes, as well as other simple black-and-white tickets.

Return
Boolean true if it should be displayed in ambient, false otherwise otherwise. The default value is false if this was never set.

getHintAvoidBackgroundClipping

fun getHintAvoidBackgroundClipping(): Boolean

Deprecated: This method has no effect starting with Wear 2.0.

Get a hint that this notification's background should not be clipped if possible, and should instead be resized to fully display on the screen, retaining the aspect ratio of the image. This can be useful for images like barcodes or qr codes.

Return
Boolean true if it's ok if the background is clipped on the screen, false otherwise. The default value is false if this was never set.

getHintContentIntentLaunchesActivity

fun getHintContentIntentLaunchesActivity(): Boolean

Get a hint that this notification's content intent will launch an Activity directly, telling the platform that it can generate the appropriate transitions

Return
Boolean true if the content intent will launch an activity and transitions should be generated, false otherwise. The default value is false if this was never set.

getHintHideIcon

fun getHintHideIcon(): Boolean

Deprecated: This method has no effect starting with Wear 2.0.

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

Return
Boolean true if this icon should not be displayed, false otherwise. The default value is false if this was never set.

getHintScreenTimeout

fun getHintScreenTimeout(): Int

Deprecated: This method has no effect starting with Wear 2.0.

Get the duration, in milliseconds, that the screen should remain on for when this notification is displayed.

Return
Int the duration in milliseconds if > 0, or either one of the sentinel values SCREEN_TIMEOUT_SHORT or SCREEN_TIMEOUT_LONG.

getHintShowBackgroundOnly

fun getHintShowBackgroundOnly(): Boolean

Deprecated: This method has no effect starting with Wear 2.0.

Get a visual hint that only the background image of this notification should be displayed, and other semantic content should be hidden. This hint is only applicable to sub-pages added using NotificationCompat.WearableExtender#addPage.

getPages

@NonNull fun getPages(): MutableList<Notification!>

Deprecated: Multiple content pages are no longer supported.

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.

Return
MutableList<Notification!> the pages for this notification

getStartScrollBottom

fun getStartScrollBottom():