NotificationCompat.WearableExtender
public
static
final
class
NotificationCompat.WearableExtender
extends Object
implements
NotificationCompat.Extender
java.lang.Object | |
↳ | 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:
- Create a
NotificationCompat.Builder
, setting any desired properties. - Create a
NotificationCompat.WearableExtender
. - Set wearable-specific properties using the
add
andset
methods ofNotificationCompat.WearableExtender
. - Call
NotificationCompat.Builder.extend(NotificationCompat.Extender)
to apply the extensions to a notification. - Post the notification to the notification
system with the
NotificationManagerCompat.notify(...)
methods and not theNotificationManager.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 | |
---|---|
int |
SCREEN_TIMEOUT_LONG
This constant is deprecated. This feature is no longer supported. |
int |
SCREEN_TIMEOUT_SHORT
This constant is deprecated. This feature is no longer supported. |
int |
SIZE_DEFAULT
This constant is deprecated. Display intents are no longer supported. |
int |
SIZE_FULL_SCREEN
This constant is deprecated. Display intents are no longer supported. |
int |
SIZE_LARGE
This constant is deprecated. Display intents are no longer supported. |
int |
SIZE_MEDIUM
This constant is deprecated. Display intents are no longer supported. |
int |
SIZE_SMALL
This constant is deprecated. Display intents are no longer supported. |
int |
SIZE_XSMALL
This constant is deprecated. Display intents are no longer supported. |
int |
UNSET_ACTION_INDEX
Sentinel value for an action index that is unset. |
Public constructors | |
---|---|
NotificationCompat.WearableExtender()
Create a |
|
NotificationCompat.WearableExtender(Notification notification)
|
Public methods | |
---|---|
NotificationCompat.WearableExtender
|
addAction(NotificationCompat.Action action)
Add a wearable action to this notification. |
NotificationCompat.WearableExtender
|
addActions(List<NotificationCompat.Action> actions)
Adds wearable actions to this notification. |
NotificationCompat.WearableExtender
|
addPage(Notification page)
This method is deprecated. Multiple content pages are no longer supported. |
NotificationCompat.WearableExtender
|
addPages(List<Notification> pages)
This method is deprecated. Multiple content pages are no longer supported. |
NotificationCompat.WearableExtender
|
clearActions()
Clear all wearable actions present on this builder. |
NotificationCompat.WearableExtender
|
clearPages()
This method is deprecated. Multiple content pages are no longer supported. |
NotificationCompat.WearableExtender
|
clone()
|
NotificationCompat.Builder
|
extend(NotificationCompat.Builder builder)
Apply wearable extensions to a notification that is being built. |
List<NotificationCompat.Action>
|
getActions()
Get the wearable actions present on this notification. |
Bitmap
|
getBackground()
This method is deprecated. Background images are no longer supported. |
String
|
getBridgeTag()
Returns the bridge tag of the notification. |
int
|
getContentAction()
Get the index of the notification action, if any, that was specified as the primary action. |
int
|
getContentIcon()
This method is deprecated. This method has no effect starting with Wear 2.0. |
int
|
getContentIconGravity()
This method is deprecated. This method has no effect starting with Wear 2.0. |
boolean
|
getContentIntentAvailableOffline()
Get whether the content intent is available when the wearable device is not connected to a companion device. |
int
|
getCustomContentHeight()
This method is deprecated. This method has no effect starting with Wear 2.0. |
int
|
getCustomSizePreset()
This method is deprecated. This method has no effect starting with Wear 2.0. |
String
|
getDismissalId()
Returns the dismissal id of the notification. |
PendingIntent
|
getDisplayIntent()
This method is deprecated. Display intents are no longer supported. |
int
|
getGravity()
This method is deprecated. This method has no effect starting with Wear 2.0. |
boolean
|
getHintAmbientBigPicture()
This method is deprecated. This feature is no longer supported. |
boolean
|
getHintAvoidBackgroundClipping()
This method is deprecated. This method has no effect starting with Wear 2.0. |
boolean
|
getHintContentIntentLaunchesActivity()
Get a hint that this notification's content intent will launch an |
boolean
|
getHintHideIcon()
This method is deprecated. This method has no effect starting with Wear 2.0. |
int
|
getHintScreenTimeout()
This method is deprecated. This method has no effect starting with Wear 2.0. |
boolean
|
getHintShowBackgroundOnly()
This method is deprecated. This method has no effect starting with Wear 2.0. |
List<Notification>
|
getPages()
This method is deprecated. Multiple content pages are no longer supported. |
boolean
|
getStartScrollBottom()
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(Bitmap background)
This method is deprecated. Background images are no longer supported. |
NotificationCompat.WearableExtender
|
setBridgeTag(String bridgeTag)
Sets a bridge tag for this notification. |
NotificationCompat.WearableExtender
|
setContentAction(int actionIndex)
Set an action from this notification's actions as the primary action. |
NotificationCompat.WearableExtender
|
setContentIcon(int icon)
This method is deprecated. This method has no effect starting with Wear 2.0. |
NotificationCompat.WearableExtender
|
setContentIconGravity(int contentIconGravity)
This method is deprecated. This method has no effect starting with Wear 2.0. |
NotificationCompat.WearableExtender
|
setContentIntentAvailableOffline(boolean contentIntentAvailableOffline)
Set whether the content intent is available when the wearable device is not connected to a companion device. |
NotificationCompat.WearableExtender
|
setCustomContentHeight(int height)
This method is deprecated. This method has no effect starting with Wear 2.0. |
NotificationCompat.WearableExtender
|
setCustomSizePreset(int sizePreset)
This method is deprecated. This method has no effect starting with Wear 2.0. |
NotificationCompat.WearableExtender
|
setDismissalId(String dismissalId)
Sets the dismissal id for this notification. |
NotificationCompat.WearableExtender
|
setDisplayIntent(PendingIntent intent)
This method is deprecated. Display intents are no longer supported. |
NotificationCompat.WearableExtender
|
setGravity(int gravity)
This method is deprecated. This method has no effect starting with Wear 2.0. |
NotificationCompat.WearableExtender
|
setHintAmbientBigPicture(boolean hintAmbientBigPicture)
This method is deprecated. This feature is no longer supported. |
NotificationCompat.WearableExtender
|
setHintAvoidBackgroundClipping(boolean hintAvoidBackgroundClipping)
This method is deprecated. This method has no effect starting with Wear 2.0. |
NotificationCompat.WearableExtender
|
setHintContentIntentLaunchesActivity(boolean hintContentIntentLaunchesActivity)
Set a hint that this notification's content intent will launch an |
NotificationCompat.WearableExtender
|
setHintHideIcon(boolean hintHideIcon)
This method is deprecated. This method has no effect starting with Wear 2.0. |
NotificationCompat.WearableExtender
|
setHintScreenTimeout(int timeout)
This method is deprecated. This method has no effect. |
NotificationCompat.WearableExtender
|
setHintShowBackgroundOnly(boolean hintShowBackgroundOnly)
This method is deprecated. This method has no effect starting with Wear 2.0. |
NotificationCompat.WearableExtender
|
setStartScrollBottom(boolean startScrollBottom)
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. |
Inherited methods | |
---|---|
Constants
SCREEN_TIMEOUT_LONG
public static final int SCREEN_TIMEOUT_LONG
This constant is deprecated.
This feature is no longer supported.
Sentinel value for use with setHintScreenTimeout(int)
to keep the screen on
for a longer amount of time when this notification is displayed on the screen.
Constant Value: -1 (0xffffffff)
SCREEN_TIMEOUT_SHORT
public static final int SCREEN_TIMEOUT_SHORT
This constant is deprecated.
This feature is no longer supported.
Sentinel value for use with setHintScreenTimeout(int)
to keep the screen on for a
short amount of time when this notification is displayed on the screen. This
is the default value.
Constant Value: 0 (0x00000000)
SIZE_DEFAULT
public static final int SIZE_DEFAULT
This constant is deprecated.
Display intents are no longer supported.
Size value for use with setCustomSizePreset(int)
to show this notification with
default sizing.
For custom display notifications created using setDisplayIntent(PendingIntent)
,
the default is SIZE_MEDIUM
. All other notifications size automatically based
on their content.
Constant Value: 0 (0x00000000)
SIZE_FULL_SCREEN
public static final int SIZE_FULL_SCREEN
This constant is deprecated.
Display intents are no longer supported.
Size value for use with setCustomSizePreset(int)
to show this notification
full screen.
This value is only applicable for custom display notifications created using
setDisplayIntent(PendingIntent)
.
Constant Value: 5 (0x00000005)
SIZE_LARGE
public static final int SIZE_LARGE
This constant is deprecated.
Display intents are no longer supported.
Size value for use with setCustomSizePreset(int)
to show this notification
with a large size.
This value is only applicable for custom display notifications created using
setDisplayIntent(PendingIntent)
.
Constant Value: 4 (0x00000004)
SIZE_MEDIUM
public static final int SIZE_MEDIUM
This constant is deprecated.
Display intents are no longer supported.
Size value for use with setCustomSizePreset(int)
to show this notification
with a medium size.
This value is only applicable for custom display notifications created using
setDisplayIntent(PendingIntent)
.
Constant Value: 3 (0x00000003)
SIZE_SMALL
public static final int SIZE_SMALL
This constant is deprecated.
Display intents are no longer supported.
Size value for use with setCustomSizePreset(int)
to show this notification
with a small size.
This value is only applicable for custom display notifications created using
setDisplayIntent(PendingIntent)
.
Constant Value: 2 (0x00000002)
SIZE_XSMALL
public static final int SIZE_XSMALL
This constant is deprecated.
Display intents are no longer supported.
Size value for use with setCustomSizePreset(int)
to show this notification
with an extra small size.
This value is only applicable for custom display notifications created using
setDisplayIntent(PendingIntent)
.
Constant Value: 1 (0x00000001)
UNSET_ACTION_INDEX
public static final int UNSET_ACTION_INDEX
Sentinel value for an action index that is unset.
Constant Value: -1 (0xffffffff)
Public constructors
NotificationCompat.WearableExtender
public NotificationCompat.WearableExtender ()
Create a NotificationCompat.WearableExtender
with default
options.
NotificationCompat.WearableExtender
public NotificationCompat.WearableExtender (Notification notification)
Parameters | |
---|---|
notification |
Notification |
Public methods
addAction
public NotificationCompat.WearableExtender addAction (NotificationCompat.Action action)
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(NotificationCompat.Action)
. This allows for customization
of which actions display on different devices.
Parameters | |
---|---|
action |
NotificationCompat.Action : the action to add to this notification |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
See also:
addActions
public NotificationCompat.WearableExtender addActions (List<NotificationCompat.Action> actions)
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(NotificationCompat.Action)
. This allows for customization
of which actions display on different devices.
Parameters | |
---|---|
actions |
List : the actions to add to this notification |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
See also:
addPage
public NotificationCompat.WearableExtender addPage (Notification page)
This method is 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 |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
See also:
addPages
public NotificationCompat.WearableExtender addPages (List<Notification> pages)
This method is 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 |
List : a list of notifications |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
See also:
clearActions
public NotificationCompat.WearableExtender clearActions ()
Clear all wearable actions present on this builder.
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining. |
See also:
clearPages
public NotificationCompat.WearableExtender clearPages ()
This method is deprecated.
Multiple content pages are no longer supported.
Clear all additional pages present on this builder.
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining. |
See also:
clone
public NotificationCompat.WearableExtender clone ()
Returns | |
---|---|
NotificationCompat.WearableExtender |
extend
public NotificationCompat.Builder extend (NotificationCompat.Builder builder)
Apply wearable extensions to a notification that is being built. This is typically
called by the NotificationCompat.Builder.extend(NotificationCompat.Extender)
method of
NotificationCompat.Builder
.
Parameters | |
---|---|
builder |
NotificationCompat.Builder : the builder to be modified. |
Returns | |
---|---|
NotificationCompat.Builder |
the build object for chaining. |
getActions
public List<NotificationCompat.Action> getActions ()
Get the wearable actions present on this notification.
Returns | |
---|---|
List<NotificationCompat.Action> |
getBackground
public Bitmap getBackground ()
This method is 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.
Returns | |
---|---|
Bitmap |
the background image |
See also:
getBridgeTag
public String getBridgeTag ()
Returns the bridge tag of the notification.
Returns | |
---|---|
String |
the bridge tag or null if not present. |
getContentAction
public int getContentAction ()
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.
Returns | |
---|---|
int |
the action index or UNSET_ACTION_INDEX if no action was selected.
|
getContentIcon
public int getContentIcon ()
This method is deprecated.
This method has no effect starting with Wear 2.0.
Get an icon that goes with the content of this notification.
Returns | |
---|---|
int |
getContentIconGravity
public int getContentIconGravity ()
This method is 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 Gravity.START
and
Gravity.END
. The default value is Gravity.END
.
Returns | |
---|---|
int |
See also:
getContentIntentAvailableOffline
public boolean getContentIntentAvailableOffline ()
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.
Returns | |
---|---|
boolean |
getCustomContentHeight
public int getCustomContentHeight ()
This method is 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(PendingIntent)
. See also setCustomSizePreset(int)
and
setCustomContentHeight(int)
.
Returns | |
---|---|
int |
getCustomSizePreset
public int getCustomSizePreset ()
This method is 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(PendingIntent)
. Check the documentation for the preset in question.
See also setCustomContentHeight(int)
and setCustomSizePreset(int)
.
Returns | |
---|---|
int |
getDismissalId
public String getDismissalId ()
Returns the dismissal id of the notification.
Returns | |
---|---|
String |
the dismissal id of the notification or null if it has not been set. |
getDisplayIntent
public PendingIntent getDisplayIntent ()
This method is 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.
Returns | |
---|---|
PendingIntent |
getGravity
public int getGravity ()
This method is 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 Gravity.TOP
,
Gravity.CENTER_VERTICAL
and Gravity.BOTTOM
.
The default value is Gravity.BOTTOM
.
Returns | |
---|---|
int |
getHintAmbientBigPicture
public boolean getHintAmbientBigPicture ()
This method is deprecated.
This feature is no longer supported.
Get a hint that this notification's NotificationCompat.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.
Returns | |
---|---|
boolean |
true if it should be displayed in ambient, false otherwise
otherwise. The default value is false if this was never set. |
getHintAvoidBackgroundClipping
public boolean getHintAvoidBackgroundClipping ()
This method is 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.
Returns | |
---|---|
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
public boolean getHintContentIntentLaunchesActivity ()
Get a hint that this notification's content intent will launch an Activity
directly, telling the platform that it can generate the appropriate transitions
Returns | |
---|---|
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
public boolean getHintHideIcon ()
This method is deprecated.
This method has no effect starting with Wear 2.0.
Get a hint that this notification's icon should not be displayed.
Returns | |
---|---|
boolean |
true if this icon should not be displayed, false otherwise.
The default value is false if this was never set. |
getHintScreenTimeout
public int getHintScreenTimeout ()
This method is 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.
Returns | |
---|---|
int |
the duration in milliseconds if > 0, or either one of the sentinel values
SCREEN_TIMEOUT_SHORT or SCREEN_TIMEOUT_LONG . |
getHintShowBackgroundOnly
public boolean getHintShowBackgroundOnly ()
This method is 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 addPage(Notification)
.
Returns | |
---|---|
boolean |
getPages
public List<Notification> getPages ()
This method is 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.
Returns | |
---|---|
List<Notification> |
the pages for this notification |
getStartScrollBottom
public boolean getStartScrollBottom ()
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).
Returns | |
---|---|
boolean |
setBackground
public NotificationCompat.WearableExtender setBackground (Bitmap background)
This method is deprecated.
Background images are no longer supported.
Set a background image to be displayed behind the notification content.
Contrary to the NotificationCompat.BigPictureStyle
, this background
will work with any notification style.
Parameters | |
---|---|
background |
Bitmap : the background bitmap |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
See also:
setBridgeTag
public NotificationCompat.WearableExtender setBridgeTag (String bridgeTag)
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. |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
setContentAction
public NotificationCompat.WearableExtender setContentAction (int actionIndex)
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.
|
Returns | |
---|---|
NotificationCompat.WearableExtender |
setContentIcon
public NotificationCompat.WearableExtender setContentIcon (int icon)
This method is deprecated.
This method has no effect starting with Wear 2.0.
Set an icon that goes with the content of this notification.
Parameters | |
---|---|
icon |
int |
Returns | |
---|---|
NotificationCompat.WearableExtender |
setContentIconGravity
public NotificationCompat.WearableExtender setContentIconGravity (int contentIconGravity)
This method is deprecated.
This method has no effect starting with Wear 2.0.
Set the gravity that the content icon should have within the notification display.
Supported values include Gravity.START
and
Gravity.END
. The default value is Gravity.END
.
Parameters | |
---|---|
contentIconGravity |
int |
Returns | |
---|---|
NotificationCompat.WearableExtender |
See also:
setContentIntentAvailableOffline
public NotificationCompat.WearableExtender setContentIntentAvailableOffline (boolean contentIntentAvailableOffline)
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.
Parameters | |
---|---|
contentIntentAvailableOffline |
boolean |
Returns | |
---|---|
NotificationCompat.WearableExtender |
setCustomContentHeight
public NotificationCompat.WearableExtender setCustomContentHeight (int height)
This method is deprecated.
This method has no effect starting with Wear 2.0.
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 setDisplayIntent(PendingIntent)
. See also
setCustomSizePreset(int)
and
getCustomContentHeight()
.
Parameters | |
---|---|
height |
int |
Returns | |
---|---|
NotificationCompat.WearableExtender |
setCustomSizePreset
public NotificationCompat.WearableExtender setCustomSizePreset (int sizePreset)
This method is deprecated.
This method has no effect starting with Wear 2.0.
Set 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(PendingIntent)
. Check the
documentation for the preset in question. See also
setCustomContentHeight(int)
and getCustomSizePreset()
.
Parameters | |
---|---|
sizePreset |
int |
Returns | |
---|---|
NotificationCompat.WearableExtender |
setDismissalId
public NotificationCompat.WearableExtender setDismissalId (String dismissalId)
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. |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
setDisplayIntent
public NotificationCompat.WearableExtender setDisplayIntent (PendingIntent intent)
This method is 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); Notification notification = new NotificationCompat.Builder(context) .extend(new NotificationCompat.WearableExtender() .setDisplayIntent(displayPendingIntent) .setCustomSizePreset(NotificationCompat.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 |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
See also:
setGravity
public NotificationCompat.WearableExtender setGravity (int gravity)
This method is deprecated.
This method has no effect starting with Wear 2.0.
Set the gravity that this notification should have within the available viewport space.
Supported values include Gravity.TOP
,
Gravity.CENTER_VERTICAL
and Gravity.BOTTOM
.
The default value is Gravity.BOTTOM
.
Parameters | |
---|---|
gravity |
int |
Returns | |
---|---|
NotificationCompat.WearableExtender |
setHintAmbientBigPicture
public NotificationCompat.WearableExtender setHintAmbientBigPicture (boolean hintAmbientBigPicture)
This method is deprecated.
This feature is no longer supported.
Set a hint that this notification's NotificationCompat.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. |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
setHintAvoidBackgroundClipping
public NotificationCompat.WearableExtender setHintAvoidBackgroundClipping (boolean hintAvoidBackgroundClipping)
This method is deprecated.
This method has no effect starting with Wear 2.0.
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. |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
setHintContentIntentLaunchesActivity
public NotificationCompat.WearableExtender setHintContentIntentLaunchesActivity (boolean hintContentIntentLaunchesActivity)
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. |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
setHintHideIcon
public NotificationCompat.WearableExtender setHintHideIcon (boolean hintHideIcon)
This method is deprecated.
This method has no effect starting with Wear 2.0.
Set a hint that this notification's icon should not be displayed.
Parameters | |
---|---|
hintHideIcon |
boolean : true to hide the icon, false otherwise. |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
setHintScreenTimeout
public NotificationCompat.WearableExtender setHintScreenTimeout (int timeout)
This method is deprecated.
This method has no effect.
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 . |
Returns | |
---|---|
NotificationCompat.WearableExtender |
this object for method chaining |
setHintShowBackgroundOnly
public NotificationCompat.WearableExtender setHintShowBackgroundOnly (boolean hintShowBackgroundOnly)
This method is deprecated.
This method has no effect starting with Wear 2.0.
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(Notification)
.
Parameters | |
---|---|
hintShowBackgroundOnly |
boolean |
Returns | |
---|---|
NotificationCompat.WearableExtender |
setStartScrollBottom
public NotificationCompat.WearableExtender setStartScrollBottom (boolean startScrollBottom)
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).
Parameters | |
---|---|
startScrollBottom |
boolean |
Returns | |
---|---|
NotificationCompat.WearableExtender |