java.lang.Object | |
↳ | android.support.v4.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:
NotificationCompat.Builder
, setting any desired
properties.
NotificationCompat.WearableExtender
.
add
and
set
methods of
NotificationCompat.WearableExtender
.
extend(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();
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | SIZE_DEFAULT |
Size value for use with
setCustomSizePreset(int)
to show this notification with
default sizing.
|
|||||||||
int | SIZE_FULL_SCREEN |
Size value for use with
setCustomSizePreset(int)
to show this notification
full screen.
|
|||||||||
int | SIZE_LARGE |
Size value for use with
setCustomSizePreset(int)
to show this notification
with a large size.
|
|||||||||
int | SIZE_MEDIUM |
Size value for use with
setCustomSizePreset(int)
to show this notification
with a medium size.
|
|||||||||
int | SIZE_SMALL |
Size value for use with
setCustomSizePreset(int)
to show this notification
with a small size.
|
|||||||||
int | SIZE_XSMALL |
Size value for use with
setCustomSizePreset(int)
to show this notification
with an extra small size.
|
|||||||||
int | UNSET_ACTION_INDEX | Sentinel value for an action index that is unset. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Create a
NotificationCompat.WearableExtender
with default
options.
|
||||||||||
|
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Add a wearable action to this notification.
|
||||||||||
|
Adds wearable actions to this notification.
|
||||||||||
|
Add an additional page of content to display with this notification.
|
||||||||||
|
Add additional pages of content to display with this notification.
|
||||||||||
|
Clear all wearable actions present on this builder.
|
||||||||||
|
Clear all additional pages present on this builder.
|
||||||||||
|
Creates and returns a copy of this
Object
.
|
||||||||||
|
Apply wearable extensions to a notification that is being built.
|
||||||||||
|
Get the wearable actions present on this notification.
|
||||||||||
|
Get a background image to be displayed behind the notification content.
|
||||||||||
|
Get the index of the notification action, if any, that was specified as being clickable
with the content of this notification.
|
||||||||||
|
Get an icon that goes with the content of this notification.
|
||||||||||
|
Get the gravity that the content icon should have within the notification display.
|
||||||||||
|
Get whether the content intent is available when the wearable device is not connected
to a companion device.
|
||||||||||
|
Get the custom height in pixels for the display of this notification's content.
|
||||||||||
|
Get the custom size preset for the display of this notification out of the available
presets found in
NotificationCompat.WearableExtender
, e.g.
|
||||||||||
|
Get the intent to launch inside of an activity view when displaying this
notification.
|
||||||||||
|
Get the gravity that this notification should have within the available viewport space.
|
||||||||||
|
Get a hint that this notification's icon should not be displayed.
|
||||||||||
|
Get a visual hint that only the background image of this notification should be
displayed, and other semantic content should be hidden.
|
||||||||||
|
Get the array of additional pages of content for displaying this notification.
|
||||||||||
|
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.
|
||||||||||
|
Set a background image to be displayed behind the notification content.
|
||||||||||
|
Set an action from this notification's actions to be clickable with the content of
this notification.
|
||||||||||
|
Set an icon that goes with the content of this notification.
|
||||||||||
|
Set the gravity that the content icon should have within the notification display.
|
||||||||||
|
Set whether the content intent is available when the wearable device is not connected
to a companion device.
|
||||||||||
|
Set the custom height in pixels for the display of this notification's content.
|
||||||||||
|
Set the custom size preset for the display of this notification out of the available
presets found in
NotificationCompat.WearableExtender
, e.g.
|
||||||||||
|
Set an intent to launch inside of an activity view when displaying
this notification.
|
||||||||||
|
Set the gravity that this notification should have within the available viewport space.
|
||||||||||
|
Set a hint that this notification's icon should not be displayed.
|
||||||||||
|
Set a visual hint that only the background image of this notification should be
displayed, and other semantic content should be hidden.
|
||||||||||
|
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.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
|||||||||||
From interface
android.support.v4.app.NotificationCompat.Extender
|
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_LARGE
. All other notifications size automatically based
on their content.
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)
.
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)
.
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)
.
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)
.
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)
.
Sentinel value for an action index that is unset.
Create a
NotificationCompat.WearableExtender
with default
options.
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
addAction(NotificationCompat.Action)
. This allows for customization
of which actions display on different devices.
action | the action to add to this notification |
---|
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
addAction(NotificationCompat.Action)
. This allows for customization
of which actions display on different devices.
actions | the actions to add to this notification |
---|
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.
page | the notification to add as another page |
---|
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.
pages | a list of notifications |
---|
Clear all wearable actions present on this builder.
Clear all additional pages present on this builder.
Creates and returns a copy of this
Object
. The default
implementation returns a so-called "shallow" copy: It creates a new
instance of the same class and then copies the field values (including
object references) from this instance to the new instance. A "deep" copy,
in contrast, would also recursively clone nested objects. A subclass that
needs to implement this kind of cloning should call
super.clone()
to create the new instance and then create deep copies of the nested,
mutable objects.
Apply wearable extensions to a notification that is being built. This is typically
called by the
extend(NotificationCompat.Extender)
method of
NotificationCompat.Builder
.
builder | the builder to be modified. |
---|
Get the wearable actions present on this notification.
Get a background image to be displayed behind the notification content.
Contrary to the
NotificationCompat.BigPictureStyle
, this background
will work with any notification style.
Get the index of the notification action, if any, that was specified as being clickable with the content of this notification. This action will no longer display separately from the notification's content.
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.
Get an icon that goes with the content of this notification.
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.
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)
.
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)
.
Get the intent to launch inside of an activity view when displaying this
notification. This
PendingIntent
should be for an activity.
Get the gravity that this notification should have within the available viewport space.
Supported values include
TOP
,
CENTER_VERTICAL
and
BOTTOM
.
The default value is
BOTTOM
.
Get a hint that this notification's icon should not be displayed.
true
if this icon should not be displayed, false otherwise.
The default value is
false
if this was never set.
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)
.
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.
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).
Set a background image to be displayed behind the notification content.
Contrary to the
NotificationCompat.BigPictureStyle
, this background
will work with any notification style.
background | the background bitmap |
---|
Set an action from this notification's actions to be clickable with the content of this notification. This action will no longer display separately from the notification's content.
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. |
---|
Set an icon that goes with the content of this notification.
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.
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()
.
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()
.
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 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 activity
|
---|
Set the gravity that this notification should have within the available viewport space.
Supported values include
TOP
,
CENTER_VERTICAL
and
BOTTOM
.
The default value is
BOTTOM
.
Set a hint that this notification's icon should not be displayed.
hintHideIcon |
true
to hide the icon,
false
otherwise.
|
---|
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)
.
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).