WearableExtender
class WearableExtender : Notification.Extender
kotlin.Any | |
↳ | android.app.Notification.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:
- Create a
android.app.Notification.Builder
, setting any desired properties. - Create a
android.app.Notification.WearableExtender
. - Set wearable-specific properties using the
add
andset
methods ofandroid.app.Notification.WearableExtender
. - Call
android.app.Notification.Builder#extend
to apply the extensions to a notification. - Post the notification to the notification system with the
NotificationManager.notify(...)
methods.
Notification notif = new Notification.Builder(mContext) .setContentTitle("New mail from " + sender.toString()) .setContentText(subject) .setSmallIcon(R.drawable.new_mail) .extend(new Notification.WearableExtender() .setContentIcon(R.drawable.new_mail)) .build(); NotificationManager notificationManger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManger.notify(0, notif);
Wearable extensions can be accessed on an existing notification by using the WearableExtender(Notification)
constructor, and then using the get
methods to access values.
Notification.WearableExtender wearableExtender = new Notification.WearableExtender( notification); List<Notification> pages = wearableExtender.getPages();
Summary
Constants | |
---|---|
static Int |
Sentinel value for use with |
static Int |
Sentinel value for use with |
static Int |
Size value for use with |
static Int |
Size value for use with |
static Int |
Size value for use with |
static Int |
Size value for use with |
static Int |
Size value for use with |
static Int |
Size value for use with |
static Int |
Sentinel value for an action index that is unset. |
Public constructors | |
---|---|
Create a |
|
WearableExtender(notif: Notification!) |
Public methods | |
---|---|
Notification.WearableExtender! |
addAction(action: Notification.Action!) Add a wearable action to this notification. |
Notification.WearableExtender! |
addActions(actions: MutableList<Notification.Action!>!) Adds wearable actions to this notification. |
Notification.WearableExtender! |
addPage(page: Notification!) Add an additional page of content to display with this notification. |
Notification.WearableExtender! |
addPages(pages: MutableList<Notification!>!) Add additional pages of content to display with this notification. |
Notification.WearableExtender! |
Clear all wearable actions present on this builder. |
Notification.WearableExtender! |
Clear all additional pages present on this builder. |
Notification.WearableExtender! |
clone() |
Notification.Builder! |
extend(builder: Notification.Builder!) Apply wearable extensions to a notification that is being built. |
MutableList<Notification.Action!>! |
Get the wearable actions present on this notification. |
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 |
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 |
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 |
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!>! |
getPages() 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. |
Notification.WearableExtender! |
setBridgeTag(bridgeTag: String!) Sets a bridge tag for this notification. |
Notification.WearableExtender! |
setContentAction(actionIndex: Int) Set an action from this notification's actions as the primary action. |
Notification.WearableExtender! |
setContentIcon(icon: Int) Set an icon that goes with the content of this notification. |
Notification.WearableExtender! |
setContentIconGravity(contentIconGravity: Int) Set the gravity that the content icon should have within the notification display. |
Notification.WearableExtender! |
setContentIntentAvailableOffline(contentIntentAvailableOffline: Boolean) Set whether the content intent is available when the wearable device is not connected to a companion device. |
Notification.WearableExtender! |
setCustomContentHeight(height: Int) Set the custom height in pixels for the display of this notification's content. |
Notification.WearableExtender! |
setCustomSizePreset(sizePreset: Int) Set the custom size preset for the display of this notification out of the available presets found in |
Notification.WearableExtender! |
setDismissalId(dismissalId: String!) Sets the dismissal id for this notification. |
Notification.WearableExtender! |
setDisplayIntent(intent: PendingIntent!) Set an intent to launch inside of an activity view when displaying this notification. |
Notification.WearableExtender! |
setGravity(gravity: Int) Set the gravity that this notification should have within the available viewport space. |
Notification.WearableExtender! |
setHintAmbientBigPicture(hintAmbientBigPicture: Boolean) Set a hint that this notification's |
Notification.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. |
Notification.WearableExtender! |
setHintContentIntentLaunchesActivity(hintContentIntentLaunchesActivity: Boolean) Set a hint that this notification's content intent will launch an |
Notification.WearableExtender! |
setHintHideIcon(hintHideIcon: Boolean) Set a hint that this notification's icon should not be displayed. |
Notification.WearableExtender! |
setHintScreenTimeout(timeout: Int) Set a hint that the screen should remain on for at least this duration when this notification is displayed on the screen. |
Notification.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. |
Notification.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 valSCREEN_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 valSCREEN_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 valSIZE_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 valSIZE_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 valSIZE_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 valSIZE_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 valSIZE_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 valSIZE_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
WearableExtender
WearableExtender()
Create a android.app.Notification.WearableExtender
with default options.
Public methods
addAction
fun addAction(action: Notification.Action!): Notification.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 android.app.Notification.Builder#addAction. This allows for customization of which actions display on different devices.
Parameters | |
---|---|
action |
Notification.Action!: the action to add to this notification |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
See Also
addActions
fun addActions(actions: MutableList<Notification.Action!>!): Notification.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 android.app.Notification.Builder#addAction. This allows for customization of which actions display on different devices.
Parameters | |
---|---|
actions |
MutableList<Notification.Action!>!: the actions to add to this notification |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
See Also
addPage
funaddPage(page: Notification!): Notification.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 | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
addPages
funaddPages(pages: MutableList<Notification!>!): Notification.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 | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
clearActions
fun clearActions(): Notification.WearableExtender!
Clear all wearable actions present on this builder.
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining. |
See Also
clearPages
funclearPages(): Notification.WearableExtender!
Deprecated: Multiple content pages are no longer supported.
Clear all additional pages present on this builder.
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining. |
See Also
clone
fun clone(): Notification.WearableExtender!
Return | |
---|---|
Notification.WearableExtender! |
a clone of this instance. |
Exceptions | |
---|---|
java.lang.CloneNotSupportedException |
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned. |
extend
fun extend(builder: Notification.Builder!): Notification.Builder!
Apply wearable extensions to a notification that is being built. This is typically called by the android.app.Notification.Builder#extend
method of android.app.Notification.Builder
.
Parameters | |
---|---|
builder |
Notification.Builder!: the builder to be modified. |
Return | |
---|---|
Notification.Builder! |
the build object for chaining. |
getActions
fun getActions(): MutableList<Notification.Action!>!
Get the wearable actions present on this notification.
getBridgeTag
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
fungetContentIcon(): Int
Deprecated: Deprecated in Java.
Get an icon that goes with the content of this notification.
getContentIconGravity
fungetContentIconGravity(): Int
Deprecated: Deprecated in Java.
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
fungetCustomContentHeight(): Int
Deprecated: Deprecated in Java.
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
fungetCustomSizePreset(): Int
Deprecated: Deprecated in Java.
Get the custom size preset for the display of this notification out of the available presets found in android.app.Notification.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
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
fungetDisplayIntent(): 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
fungetGravity(): Int
Deprecated: Deprecated in Java.
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
fungetHintAmbientBigPicture(): 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
fungetHintAvoidBackgroundClipping(): Boolean
Deprecated: Deprecated in Java.
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
fungetHintHideIcon(): Boolean
Deprecated: Deprecated in Java.
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
fungetHintScreenTimeout(): Int
Deprecated: Deprecated in Java.
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
fungetHintShowBackgroundOnly(): Boolean
Deprecated: Deprecated in Java.
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 android.app.Notification.WearableExtender#addPage
.
getPages
fungetPages(): 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(): 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. Default is false (start scroll at the top).
setBridgeTag
fun setBridgeTag(bridgeTag: String!): Notification.WearableExtender!
Sets a bridge tag for this notification. A bridge tag can be set for notifications posted from a phone to provide finer-grained control on what notifications are bridged to wearables. See Adding Wearable Features to Notifications for more information.
Parameters | |
---|---|
bridgeTag |
String!: the bridge tag of the notification. |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
setContentAction
fun setContentAction(actionIndex: Int): Notification.WearableExtender!
Set an action from this notification's actions as the primary action. If the action has a RemoteInput
associated with it, shortcuts to the options for that input are shown directly on the notification.
Parameters | |
---|---|
actionIndex |
Int: The index of the primary action. If wearable actions were added to the main notification, this index will apply to that list, otherwise it will apply to the regular actions list. |
setContentIcon
funsetContentIcon(icon: Int): Notification.WearableExtender!
Deprecated: Deprecated in Java.
Set an icon that goes with the content of this notification.
setContentIconGravity
funsetContentIconGravity(contentIconGravity: Int): Notification.WearableExtender!
Deprecated: Deprecated in Java.
Set 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
setContentIntentAvailableOffline
fun setContentIntentAvailableOffline(contentIntentAvailableOffline: Boolean): Notification.WearableExtender!
Set 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.
setCustomContentHeight
funsetCustomContentHeight(height: Int): Notification.WearableExtender!
Deprecated: Deprecated in Java.
Set the custom height in pixels for the display of this notification's content.
This option is only available for custom display notifications created using android.app.Notification.WearableExtender#setDisplayIntent
. See also android.app.Notification.WearableExtender#setCustomSizePreset
and getCustomContentHeight
.
setCustomSizePreset
funsetCustomSizePreset(sizePreset: Int): Notification.WearableExtender!
Deprecated: Deprecated in Java.
Set the custom size preset for the display of this notification out of the available presets found in android.app.Notification.WearableExtender
, e.g. SIZE_LARGE
.
Some custom size presets are only applicable for custom display notifications created using android.app.Notification.WearableExtender#setDisplayIntent
. Check the documentation for the preset in question. See also setCustomContentHeight
and getCustomSizePreset
.
setDismissalId
fun setDismissalId(dismissalId: String!): Notification.WearableExtender!
Sets the dismissal id for this notification. If a notification is posted with a dismissal id, then when that notification is canceled, notifications on other wearables and the paired Android phone having that same dismissal id will also be canceled. See Adding Wearable Features to Notifications for more information.
Parameters | |
---|---|
dismissalId |
String!: the dismissal id of the notification. |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
setDisplayIntent
funsetDisplayIntent(intent: PendingIntent!): Notification.WearableExtender!
Deprecated: Display intents are no longer supported.
Set an intent to launch inside of an activity view when displaying this notification. The PendingIntent
provided should be for an activity.
Intent displayIntent = new Intent(context, MyDisplayActivity.class); PendingIntent displayPendingIntent = PendingIntent.getActivity(context, 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); Notification notif = new Notification.Builder(context) .extend(new Notification.WearableExtender() .setDisplayIntent(displayPendingIntent) .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) .build();
The activity to launch needs to allow embedding, must be exported, and should have an empty task affinity. It is also recommended to use the device default light theme.
Example AndroidManifest.xml entry:
<activity android:name="com.example.MyDisplayActivity" android:exported="true" android:allowEmbedded="true" android:taskAffinity="" android:theme="@android:style/Theme.DeviceDefault.Light" />
Parameters | |
---|---|
intent |
PendingIntent!: the PendingIntent for an activity |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
setGravity
funsetGravity(gravity: Int): Notification.WearableExtender!
Deprecated: Deprecated in Java.
Set 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
.
setHintAmbientBigPicture
funsetHintAmbientBigPicture(hintAmbientBigPicture: Boolean): Notification.WearableExtender!
Deprecated: This feature is no longer supported.
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.
Parameters | |
---|---|
hintAmbientBigPicture |
Boolean: true to enable converstion and ambient. |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
setHintAvoidBackgroundClipping
funsetHintAvoidBackgroundClipping(hintAvoidBackgroundClipping: Boolean): Notification.WearableExtender!
Deprecated: Deprecated in Java.
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. This can be useful for images like barcodes or qr codes.
Parameters | |
---|---|
hintAvoidBackgroundClipping |
Boolean: true to avoid clipping if possible. |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
setHintContentIntentLaunchesActivity
fun setHintContentIntentLaunchesActivity(hintContentIntentLaunchesActivity: Boolean): Notification.WearableExtender!
Set a hint that this notification's content intent will launch an Activity
directly, telling the platform that it can generate the appropriate transitions.
Parameters | |
---|---|
hintContentIntentLaunchesActivity |
Boolean: true if the content intent will launch an activity and transitions should be generated, false otherwise. |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
setHintHideIcon
funsetHintHideIcon(hintHideIcon: Boolean): Notification.WearableExtender!
Deprecated: Deprecated in Java.
Set a hint that this notification's icon should not be displayed.
Parameters | |
---|---|
hintHideIcon |
Boolean: true to hide the icon, false otherwise. |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
setHintScreenTimeout
funsetHintScreenTimeout(timeout: Int): Notification.WearableExtender!
Deprecated: Deprecated in Java.
Set a hint that the screen should remain on for at least this duration when this notification is displayed on the screen.
Parameters | |
---|---|
timeout |
Int: The requested screen timeout in milliseconds. Can also be either SCREEN_TIMEOUT_SHORT or SCREEN_TIMEOUT_LONG . |
Return | |
---|---|
Notification.WearableExtender! |
this object for method chaining |
setHintShowBackgroundOnly
funsetHintShowBackgroundOnly(hintShowBackgroundOnly: Boolean): Notification.WearableExtender!
Deprecated: Deprecated in Java.
Set 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 addPage
.
setStartScrollBottom
fun setStartScrollBottom(startScrollBottom: Boolean): Notification.WearableExtender!
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. Default is false (start scroll at the top).