1 page.title=Sending and Syncing Data 2 @jd:body 3 4 <div id="tb-wrapper"> 5 <div id="tb"> 6 7 <!-- Required platform, tools, add-ons, devices, knowledge, etc. --> 8 <h2>Dependencies and prerequisites</h2> 9 <ul> 10 <li>Android 4.3 (API Level 18) or higher on the handset device</li> 11 <li>The latest version of <a href="{@docRoot}google/play">Google Play services</a></li> 12 <li>An Android Wear device or Wear AVD</li> 13 </ul> 14 </div> 15 </div> 16 17 <p> 18 The Wearable Data Layer API, which is part of Google Play services, provides a communication channel 19 for your handheld and wearable apps. The API consists of a set of data objects that the system can 20 send and synchronize over the wire and listeners that notify your apps of important events with 21 the data layer:</p> 22 23 <dl> 24 <dt><b>Data Items</b></dt> 25 <dd>A <a href="{@docRoot}reference/com/google/android/gms/wearable/DataItem.html"><code>DataItem</code></a> 26 provides data storage with automatic syncing between the handheld and 27 wearable.</dd> 28 29 <dt><b>Messages</b></dt> 30 <dd>The <a href="{@docRoot}reference/com/google/android/gms/wearable/MessageApi.html"><code>MessageApi</code></a> class 31 can send messages and is good for remote procedure calls (RPC), such as controlling a handheld's 32 media player from the wearable or starting an intent on the wearable from the handheld. 33 The system always delivers the message when the handheld and wearable are connected and delivers 34 an error when the devices are disconnected. Messages are great for one-way requests or for a 35 request/response communication model.</dd> 36 37 <dt><b>Asset</b></dt> 38 <dd><a href="{@docRoot}reference/com/google/android/gms/wearable/Asset.html"><code>Asset</code></a> objects are for 39 sending binary blobs of data, such as images. You attach assets to data items and the system 40 automatically takes care of the transfer for you, conserving Bluetooth bandwidth by caching large assets 41 to avoid re-transmission.</dd> 42 43 <dt><b>WearableListenerService</b> (for services)</dt> 44 <dd><p>Extending <a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a> 45 lets you listen for important data layer events in a service. The system manages the lifecycle of 46 the <a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a>, 47 binding to the service when it needs to send data items or messages and unbinding the service when no work is needed.</p> 48 </dd> 49 50 <dt><b>DataListener</b> (for foreground activities)</dt> 51 <dd> 52 Implementing <a href="{@docRoot}reference/com/google/android/gms/wearable/DataApi.DataListener.html"><code>DataListener</code></a> 53 in an activity lets you listen for important data layer events when an activity 54 is in the foreground. Using this instead of the 55 <a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a> 56 lets you listen for changes only when the user is actively using your app. 57 </dd> 58 </dl> 59 60 <p class="warning"><b>Warning:</b> 61 Because these APIs are designed for communication between handhelds and wearables, 62 these are the only APIs you should use to set up communication between these 63 devices. For instance, don't try to open low-level sockets to create a communication 64 channel. 65 </p> 66 67 <h2>Lessons</h2> 68 <dl> 69 <dt><a href="{@docRoot}training/wearables/data-layer/data-items.html">Accessing the Wearable Data Layer</a></dt> 70 <dd>This lesson shows you how to create a client to access the Data Layer APIs.</dd> 71 72 <dt><a href="{@docRoot}training/wearables/data-layer/data-items.html">Syncing Data Items</a></dt> 73 <dd>Data items are objects that are stored in a replicated data store that is automatically 74 synced from handhelds to wearables.</dd> 75 76 <dt><a href="{@docRoot}training/wearables/data-layer/assets.html">Transferring Assets</a></dt> 77 <dd>Assets are binary blobs of data that you typically use to transfer images or media.</dd> 78 79 <dt><a href="{@docRoot}training/wearables/data-layer/messages.html">Sending and Receiving Messages</a></dt> 80 <dd>Messages are designed for fire-and-forget messages that you can send back and forth 81 between the wearable and handheld.</dd> 82 83 <dt><a href="{@docRoot}training/wearables/data-layer/events.html">Handling Data Layer Events</a></dt> 84 <dd>Be notified of changes and events to the data layer.</dd> 85 </dl> 86 87 </div>