Book Image

Android Wearable Programming

By : Steven F. Daniel
Book Image

Android Wearable Programming

By: Steven F. Daniel

Overview of this book

Table of Contents (14 chapters)
Android Wearable Programming
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
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:

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.