Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android Wearable Programming

You're reading from   Android Wearable Programming Expand on your Android development capabilities by building applications for Android Wear

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781785280153
Length 224 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Steven F. Daniel Steven F. Daniel
Author Profile Icon Steven F. Daniel
Steven F. Daniel
Arrow right icon
View More author details
Toc

Table of Contents (8) Chapters Close

Preface 1. Understanding Android Wearables and Building Your First Android Wear App 2. Creating Notifications FREE CHAPTER 3. Creating, Debugging, and Packaging Wearable Apps 4. Sending and Syncing Data 5. Working with Google Glass 6. Designing and Customizing Interfaces for Android TV Index

Understanding the Android Wear architecture

Android Wear works by communicating wirelessly over Bluetooth between the wearable and a handheld device (typically a smartphone) running Android 4.3 or higher. When the handheld device has been paired with the wearable device, the operating system begins sending a series of notification messages automatically to the watch, along with any wearable-specific rich notification parameters, such as voice input for actions and any specific pieces that provide additional information.

When a connection has been established between the Android device and the wearable, over Google Play service, notification messages can be then exchanged between the handheld device and the wearable to trigger appropriate actions on each device.

The architecture of any typical wearable application has been set out by Google in their design guideline documents that focus primarily on the new Material design theme for Android 5.0 applications. This design document provides the developer with a comprehensive framework to create visual, motion, and interaction design across each of the various Android platforms and devices.

Since Android Wear runs as a Bluetooth Low Energy (BLE) device, developers need to ensure that they design their applications to run efficiently so that they don't impact the device's battery. This is very important when designing the custom watch faces or apps that use location service functionality.

The following image describes the architecture between the handheld device and the wearable device. In the next section, we will take a look into some of the wearable APIs that come as part of Google Play services, and explain their purpose when it comes to communicating between the mobile device and the wearable:

Understanding the Android Wear architecture

Once the connection is established, you can then start looking at sending and synching data between the two devices. When a connection between two devices has been established, each node can handle any given number of different functions. For example, one node can handle the camera part on the mobile, while another node could keep track of a user's GPS coordinates on the wearable device.

In the following list, we will explain each of the APIs, which are presented in the preceding screenshot. In later chapters, we will be using these in more depth, so at this stage, I will just be providing a brief introduction:

  • Node API: The NodeApi class is responsible for keeping track of all connected or disconnected nodes that have been established within the wearable network by using the NodeListener interface method. When a node establishes a connection between the handheld and the wearable, MessageApi quietly begins to send a message from the wearable device to the handheld device that it is paired with, which the user is signed in to with their Google account. This sends a notification to the NodeListener method that then begins to get information about each node.
  • Message API: The MessageApi class is responsible for sending across short messages to each of the connected network nodes between the wearable and the handheld device. Once a message has been received, a background listener service on the receiving side (MessageListener) will be called so that it can get the message.
  • Data API: The DataApi class is responsible for synching data between the connected Android wearable and the handheld device, and takes care of providing the synching mechanism on both sides. In addition to synching data, the big appeal of the data API is that when a user's connection gets disconnected from the paired smartphone, the data will be automatically transferred when the connection is restored, without the user needing to worry about handling data issues. When the data API receives messages from MessageApi, a background listening service on the receiving side (addListener) will be called as part of the DataListener interface method. Once the addListener method determines that a change has occurred, a call is made to the onDataChanged method.

    Note

    It is extremely important that you remember to implement WearableListenerService on both the Android wearable and the handheld device in order to listen for the events received by WearableListenerService.

    It is worthwhile to mention that all of the Android Wear APIs are included in Google Play services 5.0. It's important to note that wear itself supports only 4.3 devices and above. This is basically due to the fact that Android Wear requires Bluetooth LE, which is only available in 4.3 and above versions.

In the following chapters of this book, we will be taking a look at how to implement some of these APIs to communicate between our Android device and our wearable device, so stay tuned.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image