WAYNE PIEKARSKI: Hi.
My name is Wayne Piekarski, and I
work as a developer advocate at Google.
Today I'm going to talk about Android Wear
and how you can take advantage of stacking notifications.
Existing notifications, such as inbox style or those
that use similar summary information,
can be easily modified with just a few small changes
to your code.
This allows you to show additional information
on a wearable device that's easily glancable.
These notifications will appear as a stack
on the wearable, allowing the user to view and take
actions on each one individually,
or without having to pull your phone out of your pocket.
Before we get started, make sure you viewed the previous videos
introducing development of Android Wear.
There's more information and access
to the developer preview available from our website
here.
So now, I'm going to work through an example
of a simple messaging system for your pets.
So these are my two awesome dogs, Mila and Dillon here,
and they're going to be starring in this video.
So let's say the dogs are wearing smart collars
during the day which can send notifications to you.
On the phone, the notifications are shown together
with the total number showing in the phone's notification area.
When you click on the notification,
this brings up the application to show all the details.
On a wearable, it would be really cool
if we could look at each one separately and perhaps take
some specific action or ignore it until later.
Then there's no need to pull the phone out of our pocket.
So in this demo, you can see both the phone
and a wearable emulator running together.
On the phone, a notification is showing.
And on the wearable, you can see there's
a stack notification made up from multiple events.
You can touch the notification and it
will expand into separate messages.
You can touch the specific notification
and then swipe it to the side to see possible actions.
And when you use an action, that notification
will be dismissed, if it's been specified
to do that in your code.
You can then take a similar action
on any remaining notifications.
And remember, this can all be done while your phone remains
in your pocket by interacting with your wearable device.
So let's work through the code that
was used to create this example.
Firstly, this is the code that you would already
be using to create a notification appearing
on your phone.
One of the nice things about the Android Wear API
is that it leverages much of your existing code.
Now, we create a notification that uses a group key string.
This is a global identifier that Android uses to know,
which notification should be grouped together
on the wearable.
It can be any string that you want.
This is the first notification that
will appear on the wearable.
You start off by creating the intent and the pending intent
with whatever result you want.
This is exactly the same as you would
do for your existing notifications.
You then create the notification with the specific details
of the message, in exactly the same way
that you would have done it with your existing code.
Note that this notification is never
meant to appear on the phone, only on the wearable.
And we use the code of said action
to indicate an intent for when an action icon is
touched on the wearable display.
You then need to build a notification for the wearable
with a code of setGroup, which puts it in the group specified
previously with the string constant.
This is the second notification that appears on the wearable.
The code's basically the same except the message text
and the action are different.
And finally, we issue the notifications
to Android so they appear on the phone and the wearable.
We issue all three of them separately with unique ID
numbers.
This part of the code issues the group notification appearing
on the phone and would probably already
be in your existing code.
Make sure you use a NotificationManagerCompat
instead of the notificationManager
from the framework when you're dealing with wearable devices.
And now, we can issue the notifications
for the wearable device.
And that's it.
We're done with this example.
So you can see how easy it is to add stack notifications
to your applications.
Most of your code and APIs used remains the same,
and you can just add a little bit more
to specify the grouping.
You can use stacks in any application that
might generate many notifications that you'd
want to group together.
So some examples could be an email client,
an instant messaging application, and so forth.
There are so many other cool possibilities
of what you can do here.
This is really just the start of what I've shown here.
Android Wear is really exciting new technology,
that's going to allow all kinds of really neat applications
from developers just like you.
So you can find out more about Android Wear, and the developer
preview, by visiting our website.
You should also join our Google+ community and share your ideas
with everyone there.
I'm Wayne Piekarski, and I'm really looking forward
to seeing what kinds of awesome ideas you'll come up with.
So thanks for watching.
And I'll see you next time.