Subtitles section Play video Print subtitles Hi, my name's Justin Koh, and I'm an engineer on the Android Wear team. Let's look at how your app can let users provide voice input to notification actions with Android Wear. Before we jump in, make sure you've checked out the previous video on the basics for developing for Android Wear, including how to optimize your notifications for the wrist. And remember to check out developer.android.com where you can sign up for the developer preview, and browse the documentation. So imagine we've built a messaging app that has a reply action in new message notifications. Something like this. When a user presses reply on a phone or tablet, you would take them to a screen that would let them compose and send a reply, like this. If we don't optimize this notification for the wrist, pressing the reply action on an Android Wear device would simply open the Reply screen on your phone. But we can do better. With the remote input feature of the Android Wear API, we can hint Android Wear devices that our app can accept free form voice input in response to the notification. So here's what that looks like. Let's show the notification again, and reply from our Android Wear device. The user gets presented with a voice prompt along with a custom hint, in this case, reply to Bugdroid. They can then speak a reply like, I'll be right there, and after confirming, the reply text is sent to the app. The key here is that the app can skip the phone UI entirely, simply sending off the reply text in the background. Let's look at the code to build such a notification. First, we use the standard NotificationCompat Builder to create the notification. We'll omit the reply action for now, since we'll add it later. Next, we'll build the reply actions, PendingIntent. This intent will be started when the user presses the Reply button on the phone. Note that the intent should be for an activity, because otherwise pressing the action won't close the notification shade. Finally, we use the remote input builder and action builder classes to construct an action that will be capable of receiving voice input. Extra reply text tells Android Wear the name of an intent extra to add to the reply intent when a voice response was provided. And then we simply need to wrap our NotificationCompat builder in a wearable notification builder. That's it! To handle voice replies in your reply activity, simply check if the extra you specified earlier has any content. If it does, you know that the user responded with their voice from their Android Wear device and you can simply send the response and finish the activity immediately. Otherwise, show that activity as you normally would. And that's all there is to it. The remote input feature of the Android Wear API can help you simplify your user's lives, by providing a seamless, wrist optimized user experience for responding to notifications. There are even more APIs for customizing notifications for Android Wear devices. So be sure to check out the documentation and sample code in the developer preview on developer.android.com. Thanks and happy coding.
B1 reply android wear notification input builder DevBytes - Android Wear: Receiving Voice Replies 45 1 王愷俊 posted on 2014/04/11 More Share Save Report Video vocabulary