
CHAPTER 7
Data Layer DataMap Objects
By Michael Hahn, January 2015
The wearable data layer can sync either messages or data. A message contains a single text string, but data is typically
wrapped in a DataMap object. A DataMap is similar to a Bundle in that it contains a collection of one or more of data
types, stored as key/value pairs. Android uses a Bundle to encapsulate data exchanged between activities. Similarly,
wearable apps can use a DataMap to encapsulate the data exchanged over the wearable data layer.
Google Play services Version 5 includes a Wearable Data API that provides access to the data layer of a data com-
munications link between the two devices. App data moves down the protocol stack on the sending side, across the
bluetooth link, then up the stack on the receiving side. The following diagram shows how a handheld sends a data to
a wearable using a DataMap and the Wearable.DataApi.
On the handheld side, you start with a PutDataMapRequest. This is a helper class that simplifies the process of
creating the DataMap, DataItem, and PutDataRequest objects that are needed for sending data. On the receiving
side a WearableListener Service receives changed data and returns a buffer of DataEvents. You get a DataItem from
31
Comentarios a estos manuales