Dependencies and prerequisites
- Android 4.3 (API Level 18) or higher on the handset device
- The latest version of Google Play services
- An Android Wear device or Wear AVD
The Wearable Data Layer API, which is part of Google Play services, provides a communication channel for your handheld and wearable apps. The API consists of a set of data objects that the system can send and synchronize over the wire and listeners that notify your apps of important events with the data layer:
- Data Items
DataItemprovides data storage with automatic syncing between the handheld and wearable.
MessageApiclass can send messages and is good for remote procedure calls (RPC), such as controlling a handheld's media player from the wearable or starting an intent on the wearable from the handheld. The system always delivers the message when the handheld and wearable are connected and delivers an error when the devices are disconnected. Messages are great for one-way requests or for a request/response communication model.
Assetobjects are for sending binary blobs of data, such as images. You attach assets to data items and the system automatically takes care of the transfer for you, conserving Bluetooth bandwidth by caching large assets to avoid re-transmission.
- WearableListenerService (for services)
WearableListenerServicelets you listen for important data layer events in a service. The system manages the lifecycle of the
WearableListenerService, binding to the service when it needs to send data items or messages and unbinding the service when no work is needed.
- DataListener (for foreground activities)
DataListenerin an activity lets you listen for important data layer events when an activity is in the foreground. Using this instead of the
WearableListenerServicelets you listen for changes only when the user is actively using your app.
Warning: Because these APIs are designed for communication between handhelds and wearables, these are the only APIs you should use to set up communication between these devices. For instance, don't try to open low-level sockets to create a communication channel.
- Accessing the Wearable Data Layer
- This lesson shows you how to create a client to access the Data Layer APIs.
- Syncing Data Items
- Data items are objects that are stored in a replicated data store that is automatically synced from handhelds to wearables.
- Transferring Assets
- Assets are binary blobs of data that you typically use to transfer images or media.
- Sending and Receiving Messages
- Messages are designed for fire-and-forget messages that you can send back and forth between the wearable and handheld.
- Handling Data Layer Events
- Be notified of changes and events to the data layer.