Robert Ly | 2728c2a | 2014-06-15 22:00:13 -0700 | [diff] [blame] | 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> |
Ricardo Cervera | bf79153 | 2014-10-20 15:59:16 -0700 | [diff] [blame] | 11 | <li>The latest version of <a href="{@docRoot}google/play-services/index.html">Google Play services</a></li> |
Robert Ly | 2728c2a | 2014-06-15 22:00:13 -0700 | [diff] [blame] | 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 |
Robert Ly | e152b79 | 2014-09-15 10:46:23 -0700 | [diff] [blame] | 31 | can send messages and is good for remote procedure calls (RPC), such as controlling a handheld's |
Robert Ly | 2728c2a | 2014-06-15 22:00:13 -0700 | [diff] [blame] | 32 | media player from the wearable or starting an intent on the wearable from the handheld. |
Luan Nguyen | 050d636 | 2014-12-02 10:53:09 -0800 | [diff] [blame] | 33 | Messages are also great for one-way requests or for a request/response communication model. |
| 34 | If the handheld and wearable are connected, the system queues the message for delivery and |
| 35 | returns a successful result code. If the devices are not connected, an error is returned. A |
| 36 | successful result code does not indicate that the message was delivered successfully as the |
| 37 | devices may disconnect after receiving the result code. |
| 38 | </p></dd> |
Robert Ly | 2728c2a | 2014-06-15 22:00:13 -0700 | [diff] [blame] | 39 | |
| 40 | <dt><b>Asset</b></dt> |
| 41 | <dd><a href="{@docRoot}reference/com/google/android/gms/wearable/Asset.html"><code>Asset</code></a> objects are for |
| 42 | sending binary blobs of data, such as images. You attach assets to data items and the system |
| 43 | automatically takes care of the transfer for you, conserving Bluetooth bandwidth by caching large assets |
| 44 | to avoid re-transmission.</dd> |
| 45 | |
| 46 | <dt><b>WearableListenerService</b> (for services)</dt> |
| 47 | <dd><p>Extending <a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a> |
| 48 | lets you listen for important data layer events in a service. The system manages the lifecycle of |
| 49 | the <a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a>, |
| 50 | binding to the service when it needs to send data items or messages and unbinding the service when no work is needed.</p> |
| 51 | </dd> |
| 52 | |
| 53 | <dt><b>DataListener</b> (for foreground activities)</dt> |
| 54 | <dd> |
| 55 | Implementing <a href="{@docRoot}reference/com/google/android/gms/wearable/DataApi.DataListener.html"><code>DataListener</code></a> |
| 56 | in an activity lets you listen for important data layer events when an activity |
| 57 | is in the foreground. Using this instead of the |
| 58 | <a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a> |
| 59 | lets you listen for changes only when the user is actively using your app. |
| 60 | </dd> |
Luan Nguyen | b5890f9 | 2015-04-13 11:02:32 -0700 | [diff] [blame] | 61 | |
| 62 | <dt><b>Channel</b></dt> |
| 63 | <dd> |
| 64 | You can use the |
| 65 | <a href="{@docRoot}reference/com/google/android/gms/wearable/ChannelApi.html"><code>ChannelApi</code></a> |
| 66 | class to transfer large data items, such as music and movie files, from a handheld to a wearable |
| 67 | device. The Channel API for data transfer has the following benefits: |
| 68 | <ul> |
| 69 | <li>Transfer large data files between two or more connected devices, without |
| 70 | the automatic synchronization provided when using |
| 71 | <a href="{@docRoot}reference/com/google/android/gms/wearable/Asset.html"><code>Asset</code></a> |
| 72 | objects attached to |
| 73 | <a href="{@docRoot}reference/com/google/android/gms/wearable/DataItem.html"><code>DataItem</code></a> |
| 74 | objects. The Channel API saves disk space unlike the |
| 75 | <a href="{@docRoot}reference/com/google/android/gms/wearable/DataApi.html"><code>DataApi</code></a> |
| 76 | class, which creates a copy of the assets on the local device before synchronizing with |
| 77 | connected devices.</li> |
| 78 | <li>Reliably send a file that is too large in size to send using the |
| 79 | <a href="{@docRoot}reference/com/google/android/gms/wearable/MessageApi.html"><code>MessageApi</code></a> |
| 80 | class.</li> |
| 81 | <li>Transfer streamed data, such as music pulled from a network server or voice |
| 82 | data from the microphone.</li> |
| 83 | </ul> |
| 84 | </dd> |
Robert Ly | 2728c2a | 2014-06-15 22:00:13 -0700 | [diff] [blame] | 85 | </dl> |
| 86 | |
| 87 | <p class="warning"><b>Warning:</b> |
| 88 | Because these APIs are designed for communication between handhelds and wearables, |
| 89 | these are the only APIs you should use to set up communication between these |
| 90 | devices. For instance, don't try to open low-level sockets to create a communication |
| 91 | channel. |
| 92 | </p> |
| 93 | |
| 94 | <h2>Lessons</h2> |
| 95 | <dl> |
Ricardo Cervera | 25bf00b | 2014-10-20 14:29:42 -0700 | [diff] [blame] | 96 | <dt><a href="{@docRoot}training/wearables/data-layer/accessing.html">Accessing the Wearable Data Layer</a></dt> |
Robert Ly | 2728c2a | 2014-06-15 22:00:13 -0700 | [diff] [blame] | 97 | <dd>This lesson shows you how to create a client to access the Data Layer APIs.</dd> |
| 98 | |
| 99 | <dt><a href="{@docRoot}training/wearables/data-layer/data-items.html">Syncing Data Items</a></dt> |
| 100 | <dd>Data items are objects that are stored in a replicated data store that is automatically |
| 101 | synced from handhelds to wearables.</dd> |
| 102 | |
| 103 | <dt><a href="{@docRoot}training/wearables/data-layer/assets.html">Transferring Assets</a></dt> |
| 104 | <dd>Assets are binary blobs of data that you typically use to transfer images or media.</dd> |
| 105 | |
Robert Ly | 546d0ba | 2014-07-09 07:59:07 -0700 | [diff] [blame] | 106 | <dt><a href="{@docRoot}training/wearables/data-layer/messages.html">Sending and Receiving Messages</a></dt> |
Robert Ly | 2728c2a | 2014-06-15 22:00:13 -0700 | [diff] [blame] | 107 | <dd>Messages are designed for fire-and-forget messages that you can send back and forth |
| 108 | between the wearable and handheld.</dd> |
| 109 | |
| 110 | <dt><a href="{@docRoot}training/wearables/data-layer/events.html">Handling Data Layer Events</a></dt> |
| 111 | <dd>Be notified of changes and events to the data layer.</dd> |
| 112 | </dl> |