public static final class NotificationCompat.WearableExtender extends Object implements NotificationCompat.Extender
See Creating Notifications for Android Wear for more information on how to use this class.
To create a notification with wearable extensions:
NotificationCompat.Builder
, setting any desired
properties.
NotificationCompat.WearableExtender
.
add
and set
methods of NotificationCompat.WearableExtender
.
NotificationCompat.Builder.extend(android.support.v4.app.NotificationCompat.Extender)
to apply the extensions to a
notification.
NotificationManagerCompat.notify(...)
methods
and not the NotificationManager.notify(...)
methods.
Notification notif = 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, 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.
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(notification); List<Notification> pages = wearableExtender.getPages();
Modifier and Type | Field and Description |
---|---|
static int |
SCREEN_TIMEOUT_LONG
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. |
static int |
SCREEN_TIMEOUT_SHORT
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. |
static int |
SIZE_DEFAULT
Size value for use with
setCustomSizePreset(int) to show this notification with
default sizing. |
static int |
SIZE_FULL_SCREEN
Size value for use with
setCustomSizePreset(int) to show this notification
full screen. |
static int |
SIZE_LARGE
Size value for use with
setCustomSizePreset(int) to show this notification
with a large size. |
static int |
SIZE_MEDIUM
Size value for use with
setCustomSizePreset(int) to show this notification
with a medium size. |
static int |
SIZE_SMALL
Size value for use with
setCustomSizePreset(int) to show this notification
with a small size. |
static int |
SIZE_XSMALL
Size value for use with
setCustomSizePreset(int) to show this notification
with an extra small size. |
static int |
UNSET_ACTION_INDEX
Sentinel value for an action index that is unset.
|
Constructor and Description |
---|
WearableExtender()
Create a
NotificationCompat.WearableExtender with default
options. |
WearableExtender(Notification notif) |
Modifier and Type | Method and Description |
---|---|
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)
Add an additional page of content to display with this notification.
|
NotificationCompat.WearableExtender |
addPages(List<Notification> pages)
Add additional pages of content to display with this notification.
|
NotificationCompat.WearableExtender |
clearActions()
Clear all wearable actions present on this builder.
|
NotificationCompat.WearableExtender |
clearPages()
Clear all additional pages present on this builder.
|
NotificationCompat.WearableExtender |
clone()
Creates and returns a copy of this object.
|
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()
Get a background image to be displayed behind the notification content.
|
String |
getBridgeTag()
Returns the bridge tag of the notification.
|
int |
getContentAction()
Get the index of the notification action, if any, that was specified as being clickable
with the content of this notification.
|
int |
getContentIcon()
Get an icon that goes with the content of this notification.
|
int |
getContentIconGravity()
Get the gravity that the content icon should have within the notification display.
|
boolean |
getContentIntentAvailableOffline()
Get whether the content intent is available when the wearable device is not connected
to a companion device.
|
int |
getCustomContentHeight()
Get the custom height in pixels for the display of this notification's content.
|
int |
getCustomSizePreset()
Get the custom size preset for the display of this notification out of the available
presets found in
NotificationCompat.WearableExtender , e.g. |
String |
getDismissalId()
Returns the dismissal id of the notification.
|
PendingIntent |
getDisplayIntent()
Get the intent to launch inside of an activity view when displaying this
notification.
|
int |
getGravity()
Get the gravity that this notification should have within the available viewport space.
|
boolean |
getHintAmbientBigPicture()
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. |
boolean |
getHintAvoidBackgroundClipping()
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 |
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 |
boolean |
getHintHideIcon()
Get a hint that this notification's icon should not be displayed.
|
int |
getHintScreenTimeout()
Get the duration, in milliseconds, that the screen should remain on for
when this notification is displayed.
|
boolean |
getHintShowBackgroundOnly()
Get a visual hint that only the background image of this notification should be
displayed, and other semantic content should be hidden.
|
List<Notification> |
getPages()
Get the array of additional pages of content for displaying this notification.
|
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)
Set a background image to be displayed behind the notification content.
|
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 to be clickable with the content of
this notification.
|
NotificationCompat.WearableExtender |
setContentIcon(int icon)
Set an icon that goes with the content of this notification.
|
NotificationCompat.WearableExtender |
setContentIconGravity(int contentIconGravity)
Set the gravity that the content icon should have within the notification display.
|
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)
Set the custom height in pixels for the display of this notification's content.
|
NotificationCompat.WearableExtender |
setCustomSizePreset(int sizePreset)
Set the custom size preset for the display of this notification out of the available
presets found in
NotificationCompat.WearableExtender , e.g. |
NotificationCompat.WearableExtender |
setDismissalId(String dismissalId)
Sets the dismissal id for this notification.
|
NotificationCompat.WearableExtender |
setDisplayIntent(PendingIntent intent)
Set an intent to launch inside of an activity view when displaying
this notification.
|
NotificationCompat.WearableExtender |
setGravity(int gravity)
Set the gravity that this notification should have within the available viewport space.
|
NotificationCompat.WearableExtender |
setHintAmbientBigPicture(boolean hintAmbientBigPicture)
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. |
NotificationCompat.WearableExtender |
setHintAvoidBackgroundClipping(boolean hintAvoidBackgroundClipping)
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(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. |
NotificationCompat.WearableExtender |
setHintHideIcon(boolean hintHideIcon)
Set a hint that this notification's icon should not be displayed.
|
NotificationCompat.WearableExtender |
setHintScreenTimeout(int timeout)
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(boolean hintShowBackgroundOnly)
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(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.
|
public static final int UNSET_ACTION_INDEX
public static final int SIZE_DEFAULT
setCustomSizePreset(int)
to show this notification with
default sizing.
For custom display notifications created using setDisplayIntent(android.app.PendingIntent)
,
the default is SIZE_MEDIUM
. All other notifications size automatically based
on their content.
public static final int SIZE_XSMALL
setCustomSizePreset(int)
to show this notification
with an extra small size.
This value is only applicable for custom display notifications created using
setDisplayIntent(android.app.PendingIntent)
.
public static final int SIZE_SMALL
setCustomSizePreset(int)
to show this notification
with a small size.
This value is only applicable for custom display notifications created using
setDisplayIntent(android.app.PendingIntent)
.
public static final int SIZE_MEDIUM
setCustomSizePreset(int)
to show this notification
with a medium size.
This value is only applicable for custom display notifications created using
setDisplayIntent(android.app.PendingIntent)
.
public static final int SIZE_LARGE
setCustomSizePreset(int)
to show this notification
with a large size.
This value is only applicable for custom display notifications created using
setDisplayIntent(android.app.PendingIntent)
.
public static final int SIZE_FULL_SCREEN
setCustomSizePreset(int)
to show this notification
full screen.
This value is only applicable for custom display notifications created using
setDisplayIntent(android.app.PendingIntent)
.
public static final int SCREEN_TIMEOUT_SHORT
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.public static final int SCREEN_TIMEOUT_LONG
setHintScreenTimeout(int)
to keep the screen on
for a longer amount of time when this notification is displayed on the screen.public WearableExtender()
NotificationCompat.WearableExtender
with default
options.public WearableExtender(Notification notif)
public NotificationCompat.Builder extend(NotificationCompat.Builder builder)
NotificationCompat.Builder.extend(android.support.v4.app.NotificationCompat.Extender)
method of
NotificationCompat.Builder
.extend
in interface NotificationCompat.Extender
builder
- the builder to be modified.public NotificationCompat.WearableExtender clone()
Object
x
, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone
. If a class and all of its superclasses (except
Object
) obey this convention, it will be the case that
x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone
before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays
are considered to implement the interface Cloneable
and that
the return type of the clone
method of an array type T[]
is T[]
where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object
does not itself implement the interface
Cloneable
, so calling the clone
method on an object
whose class is Object
will result in throwing an
exception at run time.
public NotificationCompat.WearableExtender addAction(NotificationCompat.Action action)
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(int, java.lang.CharSequence, android.app.PendingIntent)
. This allows for customization
of which actions display on different devices.
action
- the action to add to this notificationNotificationCompat.Action
public NotificationCompat.WearableExtender addActions(List<NotificationCompat.Action> actions)
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(int, java.lang.CharSequence, android.app.PendingIntent)
. This allows for customization
of which actions display on different devices.
actions
- the actions to add to this notificationNotificationCompat.Action
public NotificationCompat.WearableExtender clearActions()
addAction(android.support.v4.app.NotificationCompat.Action)
public List<NotificationCompat.Action> getActions()
public NotificationCompat.WearableExtender setDisplayIntent(PendingIntent intent)
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 notif = 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" />
intent
- the PendingIntent
for an activitygetDisplayIntent()
public PendingIntent getDisplayIntent()
PendingIntent
should be for an activity.public NotificationCompat.WearableExtender addPage(Notification page)
page
- the notification to add as another pagegetPages()
public NotificationCompat.WearableExtender addPages(List<Notification> pages)
pages
- a list of notificationsgetPages()
public NotificationCompat.WearableExtender clearPages()
addPage(android.app.Notification)
public List<Notification> getPages()
public NotificationCompat.WearableExtender setBackground(Bitmap background)
NotificationCompat.BigPictureStyle
, this background
will work with any notification style.background
- the background bitmapgetBackground()
public Bitmap getBackground()
NotificationCompat.BigPictureStyle
, this background
will work with any notification style.setBackground(android.graphics.Bitmap)
public NotificationCompat.WearableExtender setContentIcon(int icon)
public int getContentIcon()
public NotificationCompat.WearableExtender setContentIconGravity(int contentIconGravity)
Gravity.START
and
Gravity.END
. The default value is Gravity.END
.setContentIcon(int)
public int getContentIconGravity()
Gravity.START
and
Gravity.END
. The default value is Gravity.END
.getContentIcon()
public NotificationCompat.WearableExtender setContentAction(int actionIndex)
For notifications with multiple pages, child pages can also have content actions set, although the list of available actions comes from the main notification and not from the child page's notification.
actionIndex
- The index of the action to hoist onto the current notification page.
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.public int getContentAction()
For notifications with multiple pages, child pages can also have content actions set, although the list of available actions comes from the main notification and not from the child page's notification.
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.
UNSET_ACTION_INDEX
if no action was selected.public NotificationCompat.WearableExtender setGravity(int gravity)
Gravity.TOP
,
Gravity.CENTER_VERTICAL
and Gravity.BOTTOM
.
The default value is Gravity.BOTTOM
.public int getGravity()
Gravity.TOP
,
Gravity.CENTER_VERTICAL
and Gravity.BOTTOM
.
The default value is Gravity.BOTTOM
.public NotificationCompat.WearableExtender setCustomSizePreset(int sizePreset)
NotificationCompat.WearableExtender
, e.g.
SIZE_LARGE
.
Some custom size presets are only applicable for custom display notifications created
using setDisplayIntent(android.app.PendingIntent)
. Check the
documentation for the preset in question. See also
setCustomContentHeight(int)
and getCustomSizePreset()
.
public int getCustomSizePreset()
NotificationCompat.WearableExtender
, e.g.
SIZE_LARGE
.
Some custom size presets are only applicable for custom display notifications created
using setDisplayIntent(android.app.PendingIntent)
. Check the documentation for the preset in question.
See also setCustomContentHeight(int)
and setCustomSizePreset(int)
.
public NotificationCompat.WearableExtender setCustomContentHeight(int height)
This option is only available for custom display notifications created
using setDisplayIntent(android.app.PendingIntent)
. See also
setCustomSizePreset(int)
and
getCustomContentHeight()
.
public int getCustomContentHeight()
This option is only available for custom display notifications created
using setDisplayIntent(android.app.PendingIntent)
. See also setCustomSizePreset(int)
and
setCustomContentHeight(int)
.
public NotificationCompat.WearableExtender setStartScrollBottom(boolean startScrollBottom)
public boolean getStartScrollBottom()
public NotificationCompat.WearableExtender setContentIntentAvailableOffline(boolean contentIntentAvailableOffline)
public boolean getContentIntentAvailableOffline()
public NotificationCompat.WearableExtender setHintHideIcon(boolean hintHideIcon)
hintHideIcon
- true
to hide the icon, false
otherwise.public boolean getHintHideIcon()
true
if this icon should not be displayed, false otherwise.
The default value is false
if this was never set.public NotificationCompat.WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly)
addPage(android.app.Notification)
.public boolean getHintShowBackgroundOnly()
addPage(android.app.Notification)
.public NotificationCompat.WearableExtender setHintAvoidBackgroundClipping(boolean hintAvoidBackgroundClipping)
hintAvoidBackgroundClipping
- true
to avoid clipping if possible.public boolean getHintAvoidBackgroundClipping()
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.public NotificationCompat.WearableExtender setHintScreenTimeout(int timeout)
timeout
- The requested screen timeout in milliseconds. Can also be either
SCREEN_TIMEOUT_SHORT
or SCREEN_TIMEOUT_LONG
.public int getHintScreenTimeout()
SCREEN_TIMEOUT_SHORT
or SCREEN_TIMEOUT_LONG
.public NotificationCompat.WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture)
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.hintAmbientBigPicture
- true
to enable converstion and ambient.public boolean getHintAmbientBigPicture()
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.true
if it should be displayed in ambient, false otherwise
otherwise. The default value is false
if this was never set.public NotificationCompat.WearableExtender setHintContentIntentLaunchesActivity(boolean hintContentIntentLaunchesActivity)
Activity
directly, telling the platform that it can generate the appropriate transitions.hintContentIntentLaunchesActivity
- true
if the content intent will launch
an activity and transitions should be generated, false otherwise.public boolean getHintContentIntentLaunchesActivity()
Activity
directly, telling the platform that it can generate the appropriate transitionstrue
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.public NotificationCompat.WearableExtender setDismissalId(String dismissalId)
dismissalId
- the dismissal id of the notification.public String getDismissalId()
public NotificationCompat.WearableExtender setBridgeTag(String bridgeTag)
bridgeTag
- the bridge tag of the notification.public String getBridgeTag()