Android Wear: w00h00 new toys!

Android Wear: w00h00 new toys!

As you may have noticed, the Android Wear watches were announced at Google I/O this week. Google has also shown what else you can do with them besides look at your gorgeous notifications from your phone on your wrist.

As a partner of Google’s we’ve had the opportunity to preview the full package over the past few weeks while building the Hue Control app (available from July 7th). The following is a writeup of what the new Android Wear has in store.

Android Wear watches?

Basically, these watches are a full-color touch Android device strapped to your wrist. In its most basic form, you get your phone notifications on your wrist. You can swipe up and down through them and if they have actions attached (like reply, navigate to, etc.) you can go through them by swiping horizontally. Swiping right on the first page of the notification will dismiss it, both on the watch and on the phone.

One extra thing you can do with these actions (which you can’t do for the notification on your phone I believe) is add a voice control action to the notification. Once you tap this on your watch, you can then either activate free speech input or display a list of commands the user can trigger with his or her voice. The spoken command is then delivered to your phone app as a string. This is a great way to save the user from having to flick through a list of all available commands.

Okay, cool. So I pay 200 bucks just to see my notifications on another device?” Well no. These devices run Android, so you can build something specifically for them. There won’t be a separate store for your Wear apps; the cool thing is that they’re bundled right along with your phone app. If the phone is paired to a Wear device, it silently installs the Wear part of the app. Which is pretty cool.

Hopefully Google will provide a way to block certain apps however, since I might not want a Twitter app on my Wear but would like to keep the original app on my phone.

I wanna build my own Wear app!

Right. Basically you just build an Android app. However, the device it’s going to run on will lack certain things, like internet connectivity for example. The idea is that the watch extends your phone’s capabilities rather than replacing them. If you want access to your phone’s capabilities (internet, GPS, etc.), you can use the DataLayer API.

Talking to the outside world

There are two ways to send data between the Wear device and the phone. One is by simply sending messages which are just strings with some extra data formatted in a byte array. A second option is by sending DataItems.

The way these work is that you post a DataMap to a path name, for example: ‘/groups’ or ‘/group/’. DataMaps are like Android’s bundles which means you can post strings, booleans, integers and other DataMaps or even lists of DataMaps. On the other side of the connection you’ll get an onDataChanged event which has the DataItem which just changed.

A good thing to keep in mind here is that it caches the DataItems sent to and from the device. It also only pushes data to the device if the data on that specific path actually changed. If you push exactly the same data, the onDataChanged event won’t trigger.

In the case of our Hue app, we always want to send the user input from the watch to the phone. It can very well be that a different device has changed the settings of your lights since you selected a preset, and selecting that same preset later will have no effect. We ended up fixing this by adding a timestamp parameter that’s unique and forces the message through.

Start your engines!

There are a few ways users can enter your app. One is by saying ‘OK Google, start my awesome app’. A second option is to register as a default voice command like ‘OK Google, take a note with my awesome app’. Third, opening your app can be an action associated with a notification. Lastly the Wear app can be opened by sending a message via the DataLayer API.

Notifications

By default, all notifications that your app pushes are displayed on both your phone and your watch. If you want to have a notification appear only on the watch you have the setLocalOnly(true) function on the notification builder. This only works from the device the notification was pushed from. If you pushed the notification from your phone, with that setting it will only appear on your phone. So in order to only have it appear on your watch you need to send the message through the data layer, and then push the notification from the watch.

These are a few of the lessons we learned while adding Android Wear support to our Hue Control app. From July 7th you can see the end result in action by downloading Hue Control from the App Store.