Wearable apps run directly on the wearable device, giving you access to low-level hardware such as sensors, activities, services, and more, right on the wearable.
A companion handheld app that contains the wearable app is also required when you want to publish to the Google Play store. Wearables don't support the Google Play store, so users download the companion handheld app, which automatically pushes the wearable app to the wearable. The handheld app is also useful for doing heavy processing, network actions, or other work and sending the results to the wearable.
This lesson goes over how to set up a device or emulator and create one project to contain both your wearable and handheld apps.
Set Up an Android Wear Emulator or Device
We recommend that you develop on real hardware so you can better gauge the user experience. However, the emulator lets you test out different types of screen shapes, which is useful for testing.
Set up an Android Wear Virtual Device
To set up an Android Wear virtual device:
- Click Tools > Android > AVD Manager.
- Click Create....
- Fill in the following details for the AVD you want to specify and leave the rest
of the fields with their default values:
- AVD Name - A name for your AVD
- Device - Android Wear Round or Square device types
- Target - Android 4.4W - API Level 20
- CPU/ABI - Android Wear ARM (armeabi-v7a)
- Keyboard - Select Hardware keyboard present
- Skin - AndroidWearRound or AndroidWearSquare depending on the selected device type
- Snapshot - Not selected
- Use Host GPU - Selected, to support custom activities for wearable notifications
- Click OK.
- Start the emulator:
- Select the virtual device you just created.
- Click Start..., then click Launch.
- Wait until the emulator initializes and shows the Android Wear home screen.
- Pair Your handheld with the emulator:
- On your handheld, install the Android Wear app from Google Play.
- Connect the handheld to your machine through USB.
- Forward the AVD's communication port to the connected handheld device (you must
do this every time the handheld is connected):
adb -d forward tcp:5601 tcp:5601
- Start the Android Wear app on your handheld device and connect to the emulator.
- Tap the menu on the top right corner of the Android Wear app and select Demo Cards.
- The cards you select appear as notifications on the home screen of the emulator.
Set Up an Android Wear Device
To set up an Android Wear device:
- Install the Android Wear app, available on Google Play, on your handheld.
- Follow the app's instructions to pair your handheld with your wearable. This allows you to test out synced handheld notifications, if you're building them.
- Leave the Android Wear app open on your phone.
- Connect the wearable to your machine through USB, so you can install apps directly to it as you develop. A message appears on both the wearable and the Android Wear app prompting you to allow debugging.
- On the Android Wear app, check Always allow from this computer and tap OK.
The Android tool window on Android Studio shows the system log from the wearable.
The wearable should also be listed when you run the
adb devices command.
Create a Project
To begin development, create an app project that contains wearable and handheld app modules. In Android Studio, click File > New Project and follow the Project Wizard instructions, as described in Creating a Project. As you follow the wizard, enter the following information:
- In the Configure your Project window, enter a name for your app and a package name.
- In the Form Factors window:
- Select Phone and Tablet and select API 9: Android 2.3 (Gingerbread) under Minimum SDK.
- Select Wear and select API 20: Android 4.4 (KitKat Wear) under Minimum SDK.
- In the first Add an Activity window, add a blank activity for mobile.
- In the second Add an Activity window, add a blank activity for Wear.
When the wizard completes, Android Studio creates a new project with two modules, mobile and wear. You now have a project for both your handheld and wearable apps that you can create activities, services, custom layouts, and much more in. On the handheld app, you do most of the heavy lifting, such as network communications, intensive processing, or tasks that require long amounts of user interaction. When these are done, you usually notify the wearable of the results through notifications or by syncing and sending data to the wearable.
Note: The wear module also contains a "Hello World" activity that uses a
WatchViewStub that inflates a layout based on whether the device's screen
is round or square. The
WatchViewStub class is one of the UI widgets that's provided
by the wearable support library.
Install the Wearable App
When developing, you install apps directly to the wearable like with handheld apps. Use
adb install or the Play button on Android Studio.
When you're ready to publish your app to users, you embed the wearable app inside of the handheld app. When users install the handheld app from Google Play, a connected wearable automatically receives the wearable app.
Note: The automatic installation of wearable apps does not work when you are signing apps with a debug key and only works with release keys. See Packaging Wearable Apps for complete information on how to properly package wearable apps.
Include the Correct Libraries
As part of the Project Wizard, the correct
dependencies are imported for you in the appropriate module's
However, these dependencies are not required, so read the following descriptions to find out if you need them or not:
The Android v4 support library (or v13, which includes v4) contains the APIs to extend your existing notifications on handhelds to support wearables.
For notifications that appear only on the wearable (meaning, they are issued by an app that runs on the wearable), you can just use the standard framework APIs (API Level 20) on the wearable and remove the support library dependency in the mobile module of your project.Wearable Data Layer
To sync and send data between wearables and handhelds with the Wearable Data Layer APIs, you need the latest version of Google Play services. If you're not using these APIs, remove the dependency from both modules.Wearable UI support library
This is an unofficial library that includes UI widgets designed for wearables. We encourage you to use them in your apps, because they exemplify best practices, but they can still change at any time. However, if the libraries are updated, your apps won't break since they are compiled into your app. To get new features from an updated library, you just need to statically link the new version and update your app accordingly. This library is only applicable if you create wearable apps.
In the next lessons, you'll learn how to create layouts designed for wearables as well as how to use the various voice actions that are supported by the platform.