Building Your First Wearable Android App

Tuesday May 19th 2015 by Chunyen Liu

Follow along and go through the necessary setup on mobile and wearable devices as well as configurations on Android Studio.

Wearable devices are gaining more momentum, especially after Google released its Android Wear platform for developers. Smart watches powered by this platform are among the most affordable for consumers and thus we are seeing new models in the market more often than ever. The low-cost sensors, versatile connectivity, and even the fashionable designs are making this technology very accessible and appealing. Even Apple also has its own smart watches in this wearable device competition and Google is pushing more new features for Android Wear; for example, Wi-Fi connectivity, wrist gestures for navigation, and so on. Now is definitely a great time to dive into this technology. As mentioned in a previous article, the Android Wear platform is only made available for its own IDE in Android Studio, so if you need the related info, please refer to "Using Android Studio".

This tutorial will go through the necessary setup on mobile and wearable devices as well as configurations on Android Studio. A complete example will follow to illustrate how the development process works.

Setup on Android Studio

First, check is whether you have the required Android SDK. Although Android 4.4W (API 20) works as a minimum level for you to start using Android Wear platform, I would still recommend you get the latest and greatest APIs. In Android Studio, under the system menu "Tools -> Android -> SDK Manager", you can check if you have API 20 and above installed, as shown in Figure 1.

Next, if you do not have a Android Wear powered smart device, we need to create an Android virtual device (AVD) for our testing purpose. Under the same menu as described previously, select "AVD Manager" and then select "Create Virtual Device..." with all the default values for now. The example is in Figure 2.


Figure 1: SDK Manager

Figure 2: Android Wear AVD

Setup on Mobile Devices

The only required companion app for your mobile phone is Android Wear. It is free and downloadable through the Google Play store. Start the app and you can connect with wearable devices guided by on-screen step-by-setp instructions. It also provides direct control for your device settings as well as links to more wearable apps. Now, you can establish the debugging connection with the virtual device we created in the last section through the DOS command line "adb -d forward tcp:5601 tcp:5601".

Figure 3: Android Wear App

Setup on Wearable Devices

On your Android Wear powered device, go to "Settings -> About" and tap on "Build Number" several times till your device tells you it is about to switch on the developer option. Then, go to your "Developer Options" and enable "ADB debugging" as well as "Debug over Bluetooth", as in Figure 4. Connect your wearable device with your mobile phone through the Android Wear app. Also, enable "Debug over Bluetooth" in the app settings.

Finally, from the DOS command line, type "adb forward tcp:4444 localabstract:/adb-hub" and then "adb connect localhost:4444", as in Figure 5. You will see your wearable device listed as "localhost:4444". For your information, the other listed device "05e30f613444cc5e" is my mobile phone, a Nexus 5.

Figure 4: Wearable Device Settings

Figure 5: Wearable Device Debugging Connection

A Working Example

After all the initial setups, we now are ready to start building our first wearable project. Click on "Start a new Android Studio project" on Android Studio and name our project "Scientist". Check the target devices for "Phone and Tablet" and "Wear". Simply use the default mobile and wear blank activities as our templates. The main layout file, activity_scientist_wear.xml, for the wear module is as follows. You can see it contains links to both round and square layouts.

<?xml version="1.0" encoding="utf-8"?>
      tools" android:id="@+id/watch_view_stub"

For example, the round layout file, round_activity_scientist_wear.xml, for the wear module should be similar to this.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas."
   android:layout_height="match_parent" tools:context=

   <TextView android:id="@+id/text"
         android:text="@string/hello_round" />

The main activity is named ScientistWearActivity. It uses one of the most powerful APIs for the wearable interface experience by adding speech recognition capability and trying to interpret the free-form speech result. Of course, the Android Wear platform already provides a list of voice intents in the system that are ready for use. Developers can define their own app-provided voice actions as well. Starting the speech recognizer is simple and straightforward as other handy intents. In "startSpeechRecognizer()", it prompts a question about "Who is the key scientist in the movie The Imitation Game?" and waits for free-form voice input. The result returned by the speech recognizer is captured by "onActivityResult()". It then responds with a message depending on whether the recognized speech text contains the scientist's name in "Alan Turing". Figures 6 and 7 show the screen shots while the app is in action.

public class ScientistWearActivity extends Activity {

   private static final int SPEECH_RECOGNIZER
      _REQUEST_CODE = 3000;
   private TextView mTextView;

   protected void onCreate(Bundle savedInstanceState) {
      final WatchViewStub stub = (WatchViewStub)
            WatchViewStub.OnLayoutInflatedListener() {
         public void onLayoutInflated(WatchViewStub stub) {
            mTextView = (TextView)

   private void startSpeechRecognizer() {
      Intent intent = new Intent
         "Imitation Game\nScientist");

   protected void onActivityResult(int requestCode,
         int resultCode, Intent data) {
      if (requestCode == SPEECH_RECOGNIZER_REQUEST_CODE) {
         if (resultCode == RESULT_OK) {
            List<String> results =
            String theText = results.get(0);
            if (theText.toUpperCase().indexOf("ALAN TURING") > -1)
               mTextView.setText("Correct!\nIt is Alan Turing.");
               mTextView.setText("Incorrect!\nIt is Alan Turing.");
      super.onActivityResult(requestCode, resultCode, data);

Figure 6: App Start

Figure 7: App Result


The Android Wear platform is by far the most popular and widely used development tool for wearable devices among developers. There are already millions of smart devices powered by it out there in the market: smart watches, glass, fitness trackers, and so forth. With Apple stepping into the competition, we are only going to see this wearable technology continue to grow at a fierce speed. Well, it is not too late for the game yet. Get ready to be creative and productive with the new upcoming devices.


About the Author

Chunyen Liu has been a software professional in Taiwan and the United States. He is a published author of 30+ articles and 100+ tiny apps, software patentee, technical reviewer, and programming contest winner by ACM/IBM/SUN. He holds advanced Computer Science degrees and trained in 20+ graduate-level courses. On the non-technical side, he is a certified coach, certified umpire, and rated player of USA Table Tennis, having won categorized events at State Championships and US Open.

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved