Tip:
Highlight text to annotate it
X
Hi.
I'm Griff Hazen, an engineer with the Android Wear project.
My team has been working on APIs to create rich notification
experiences for Android Wear devices.
Let's look at three aspects of Wearable notifications.
New display options, new features for notification
actions, and advanced customization.
This is the notifications stream, a great way
to get information and interactions in front of users.
There's a vertical list of notifications
of all shapes and sizes.
To access a notification, swipe up from the watch face.
Continuing to swipe will reveal additional cards.
Notifications in the stream are added
using the Android Notifications API.
If you're already familiar with this API,
you may recognize some of its features.
For example, notification actions
are available to the right of a notifications
card on a separate screen.
But just like on phones and tablets,
notifications can still be dismissed
by pushing the notification card to the side and releasing.
Notifications on the phone automatically
sync to your watch.
This allows many existing Android apps to already provide
value on the wearable.
This extends to actions and dismissals, too.
We support many of the existing notification styles,
like Inbox, Big Picture, and Big Text.
When content is too long, users can
tap the notification to expand it.
To make richer experiences, we've
also added new APIs to customize notifications.
They are part of the new Wearable Extensions
Classes in the Android SDK and Support library.
Let's take a look at some of these.
First off, we have multi-page notifications.
Pages can be used to add further detail
to a single notification.
They can be accessed by swiping.
Indicators at the bottom of the screen
show the user which page they are on.
Since pages are just notification objects,
they can use any of the notification styles.
To add pages to a notification, use the Add Page Method
of the new Wearable Extender Class.
This code snippet adds two additional pages of content,
making for a total of three cards.
Also, as you saw in the previous animation,
you can add a page that is just a full-screen image
with no card.
This can be useful for imagery like a map or a photograph.
When creating the notification for an image-only page,
call setBackground to select a bitmap,
and also call setHintShowBackgroundOnly
to hide its card.
Pages were useful for adding details
to a single notification.
Another new feature, Notification Stacks,
allows grouping of multiple notifications together.
Users can interact with the entire stack,
or they can drill into individual items.
Actions can be added to the stack itself
and to child notifications.
This feature can be very handy for messaging apps
where users may want to interact with all of your messages
at once or with just one.
To create a Notification Stack, post one or more child
notifications and tag them all with the seem group key.
You can do this by using the setGroupMethod
of NotificationCompat.Builder.
Notifications posted with the same group
key from the same app will be included in the same stack.
You can also call setSortKey to arrange your items.
If you would like to select the background image and actions
for a bundle, you can post an optional group summary
notification.
In this case, the user will see the Archive All
action for the bundle.
Make sure to select a unique notification ID
or tag for each notification, otherwise they
will override each other when posted.
The notification actions shown so far
have all used the default behavior,
which is to be appended as additional pages
to the right of other cards.
The watch on the left shows this behavior.
Swiping past the main card reveals the pause action.
The watch on the right, however, shows action directly attached
to the existing card.
It makes the entire card clickable.
Use setContentAction of Wearable Extender
to place an action on a card.
These actions are no longer displayed as separate pages.
Remote input is another new feature
of notification actions.
It allows the collection of text responses
from users when they trigger an action.
Users will be prompted to speak a phrase
or select from a set of choices.
The result of this input is sent along
with your actions pending intent.
Remote input is an easy way to add Android
Wear voice interaction to apps for phone, tablet, or wearable.
The code snippet shown adds a remote input
to the reply action.
When a user taps this action in the stream,
they'll be prompted to provide voice input under the label
Quick Reply.
Once text is transcribed and the user approves it,
your action intent fires and it will contain the results.
The recipient of your intent, be it
an activity, service, or broadcast receiver,
can use the Get Results from Intent function
of the remote input API to retrieve the result text.
In the code snippet, the variable quickReplyText
will be set to the users' input.
There are a variety of other options
available in the remote input API,
including support for preset choices,
enabling or disabling, free form input,
and support for more than one input on the same action.
The standard notification templates
may not be sufficient for the content
you'd like to display in a card.
So we've added a new API, set Display Intent.
It lets you draw the content of a notification
card in real time using an Android activity.
This feature is only available for apps
running on the Wearable.
And these apps need to target API level 20.
When defining an activity to embed within a custom display
card, you must first mark it as exported.
This can be accomplished by setting the exported attribute
on the activities to true or by adding an intent filter.
Next, set the new attribute allow embedded to true.
This prevents activities from being
embedded that weren't meant to be.
And finally, set task Affinity to the empty string.
These activities can contain the same content
as other activities, although touch input won't propagate
when in the stream, so controls like buttons are probably
not appropriate.
Once you've written your activity,
you can embed it within the stream, create a notification,
and use the setDisplayIntent method of a wearable extender
object to select that activity.
You can pass any needed data to your activity
by adding extras to the display intent.
Here are some examples of custom display notifications.
Standard notifications in the stream
automatically size based on their contents.
But custom display notifications need
to provide a size if the default large size is not desired.
You can use the set custom size preset or the set custom
content height methods of wearable extender
to select a size.
With the exception of custom display cards,
the APIs described in this video can
be used with notifications created both from wearable apps
and with notifications bridged from phone or tablet apps.
Bridging a phone and tablet notifications to wearables
is automatic, but there are a couple new APIs
to customize bridging behavior.
First off, you can disable bridging
for a notification entirely using
the new set Local Only method of notification Compat Builder.
This is useful for notifications that are not
relevant outside of the current device.
A second feature is the ability to add wearable only actions
to a notification.
This lets you select a separate set
of actions for the phone and the wearable.
Wearable only actions are added using the Wearable Extender
Class.
In this talk, we've gone through a number of new notification
features added for Android Wear.
I hope it has provided ideas for how to enhance an existing
Android app and notifications for wearable devices,
and also ideas for new wearable experiences.
More information about these APIs and design principles can
be found on the Android Wear Developer site
at developer.android.com/wear.
I'm Griff Hazen, and thank you for watching.