Android Wear SDK and Google Fit APIs

The wearable technology is a hot topic right now, many companies have tried to bring this technology to us, it’s not only improves the user experience on the certain apps like steps count, music players, notifications, and so on, but also, they can generate amount of data which cannot be tracked by other devices such as heart rate, sleeping time, and calorie consumption… Especially, at some circumstance when people are not able to hold their phone on the hand, wearable devices can be a good solution.

In this blog, I will mainly focus on the smartwatch of wearable devices which is on the Android wear OS platform.

What are the advantages of smartwatch app?

First, I would say notification. No matter what kind of calendar or reminder apps you are using right now, you still miss notifications. Because when you are running to the next class you don’t want to pull out your phone, when you are on a class you need switch your phone to silence model, when you are working out you don’t feel the vibrations. However, a smartwatch can solve all the problems above. You can just set a reminder anytime even during the class time and it will just give you a little vibration on your hand and shows everything on glance with no sound and any disturbance to others.

Second, Liveness. I was not so sure how to describe this important feature before, but after the lectures about liveness in class I would say this is liveness. Imagine that when you tracking something like How many steps you have walked today? How about you friends, what’s their steps? How much time you get for your project? or How soon it my next exam? I know that there are tons of apps you can find in app store to track those things. However, they all have a flaw which is you need to unlock you phone, open the app and load the data. They are not live. Here is a picture I developed for steps count app on Android Watch OS.

3:12 is time

1799 is user steps, with big white circle

642 is friend1 steps with red circle

2000 is friend2 steps with blue circle

1764 is friend3 steps with green circle

3067 is steps left for daily goal

5.56 is the ratio of monthly goal with little inner white circle

 

As you can see the steps are showing by both numbers and visual graphs, and they will just like the pointers on a mechanical watch when you walk a step the number add one and the graph moves a step. This picture above is your glance screen, when you want to know the information you just raise your hand. The simplest way to track what you want and keep them always under your eyes.

https://www.youtube.com/watch?v=si6ZNFXJ_TQ

 

Developing on Watch OS

First, you need to download the Android studio SDK. Then, you just open the studio, start a new android Studio project, on the next page choose wear instead of phone or tablet. After that you have couple options for what kind of app you want to build, google has already write some APIs for you if you want to do google map app, if you don’t know which one to choose you can simply choose blank activity and you can add those later.

      

      

 

Then, you can create your watch interaction interface by writing a xml files in the wear>res>layout folder. However, in android watch we need to use the Canvas class which holds the “draw” calls, to design the glance screen. Because this part of the interface is dynamic, it means the interface is changing with the data updates. For example, the pointers on the clock view. For each tick, the pointers rotate a certain degree of angle on the clock by the rotation function which will call canvas class to draw the new movement on the clock view. All the UIs that wrote by canvas can dynamically moves by java functions.

Furthermore, like I said before there areseveral data we can track by a smartwatch. The question is how can we use them? Google has offered us some great APIs. For instance, instead of writhing you own step counting functions which is not easy like it sounds you need to use accelerometer sensor and physic mode functions, you could just implement Google Fitness API. It will upload your data to their sever and send back the result to your background services. You just need to update your Canvas draw with the data you receive. Also, you can use google API console to track further information.

Also, I found google has updated many of their fit APIs since the past year and now they have not only the Fitness data, but also the Nutrition and Health data like blood pressure. They use some special algorithms to calculate those data with the sensors we have on our phone, it saves a lot of time when developers try to access those kinds of data.

I think this is great resource for people who are interested in android development, especially on smartwatches. I hope the blog gives you the basic idea how the phones, watches and APIs work together, and how useful it is when you are developing your project.

 

 

Resource for this blog:

https://developer.android.com/studio/

https://developer.android.com/distribute/console/

https://developers.google.com/fit/scenarios/record-steps