124 lines
6.5 KiB
Plaintext
124 lines
6.5 KiB
Plaintext
page.title=Sending and Syncing Data
|
||
@jd:body
|
||
|
||
<div id="tb-wrapper">
|
||
<div id="tb">
|
||
|
||
<!-- Required platform, tools, add-ons, devices, knowledge, etc. -->
|
||
<h2>Dependencies and prerequisites</h2>
|
||
<ul>
|
||
<li>Android 4.3 (API Level 18) or higher on the handset device</li>
|
||
<li>The latest version of <a href="{@docRoot}google/play-services/index.html">Google Play services</a></li>
|
||
<li>An Android Wear device or Wear AVD</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
<p>
|
||
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:</p>
|
||
|
||
<dl>
|
||
<dt><b>Data Items</b></dt>
|
||
<dd>A <a href="{@docRoot}reference/com/google/android/gms/wearable/DataItem.html"><code>DataItem</code></a>
|
||
provides data storage with automatic syncing between the handheld and
|
||
wearable.</dd>
|
||
|
||
<dt><b>Messages</b></dt>
|
||
<dd>The <a href="{@docRoot}reference/com/google/android/gms/wearable/MessageApi.html"><code>MessageApi</code></a> class
|
||
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.
|
||
Messages are also great for one-way requests or for a request/response communication model.
|
||
If the handheld and wearable are connected, the system queues the message for delivery and
|
||
returns a successful result code. If the devices are not connected, an error is returned. A
|
||
successful result code does not indicate that the message was delivered successfully as the
|
||
devices may disconnect after receiving the result code.
|
||
</p></dd>
|
||
|
||
<dt><b>Asset</b></dt>
|
||
<dd><a href="{@docRoot}reference/com/google/android/gms/wearable/Asset.html"><code>Asset</code></a> objects 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.</dd>
|
||
|
||
<dt><b>WearableListenerService</b> (for services)</dt>
|
||
<dd><p>Extending <a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a>
|
||
lets you listen for important data layer events in a service. The system manages the lifecycle of
|
||
the <a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a>,
|
||
binding to the service when it needs to send data items or messages and unbinding the service when no work is needed.</p>
|
||
</dd>
|
||
|
||
<dt><b>DataListener</b> (for foreground activities)</dt>
|
||
<dd>
|
||
Implementing <a href="{@docRoot}reference/com/google/android/gms/wearable/DataApi.DataListener.html"><code>DataListener</code></a>
|
||
in an activity lets you listen for important data layer events when an activity
|
||
is in the foreground. Using this instead of the
|
||
<a href="{@docRoot}reference/com/google/android/gms/wearable/WearableListenerService.html"><code>WearableListenerService</code></a>
|
||
lets you listen for changes only when the user is actively using your app.
|
||
</dd>
|
||
|
||
<dt><b>Channel</b></dt>
|
||
<dd>
|
||
You can use the
|
||
<a href="{@docRoot}reference/com/google/android/gms/wearable/ChannelApi.html"><code>ChannelApi</code></a>
|
||
class to transfer large data items, such as music and movie files, from a handheld to a wearable
|
||
device. The Channel API for data transfer has the following benefits:
|
||
<ul>
|
||
<li>Transfer large data files between two or more connected devices, without
|
||
the automatic synchronization provided when using
|
||
<a href="{@docRoot}reference/com/google/android/gms/wearable/Asset.html"><code>Asset</code></a>
|
||
objects attached to
|
||
<a href="{@docRoot}reference/com/google/android/gms/wearable/DataItem.html"><code>DataItem</code></a>
|
||
objects. The Channel API saves disk space unlike the
|
||
<a href="{@docRoot}reference/com/google/android/gms/wearable/DataApi.html"><code>DataApi</code></a>
|
||
class, which creates a copy of the assets on the local device before synchronizing with
|
||
connected devices.</li>
|
||
<li>Reliably send a file that is too large in size to send using the
|
||
<a href="{@docRoot}reference/com/google/android/gms/wearable/MessageApi.html"><code>MessageApi</code></a>
|
||
class.</li>
|
||
<li>Transfer streamed data, such as music pulled from a network server or voice
|
||
data from the microphone.</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
|
||
<p class="warning"><b>Warning:</b>
|
||
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.
|
||
</p>
|
||
|
||
<p>Android Wear supports multiple wearables connected to a handheld device. For example, when the
|
||
user saves a note on a handheld, it automatically appears on both of the user's Wear devices. To
|
||
synchronize data between devices, Google’s servers host a cloud node in the network of devices. The
|
||
system synchronizes data to directly connected devices, the cloud node, and to wearable devices
|
||
connected to the cloud node via Wi-Fi.</p>
|
||
|
||
<img src="{@docRoot}wear/images/wear_cloud_node.png" alt="" width="330" height="375"/>
|
||
<p class="img-caption"><strong>Figure 1.</strong> A sample network of nodes with
|
||
handheld and wearable devices.</p>
|
||
|
||
|
||
<h2>Lessons</h2>
|
||
<dl>
|
||
<dt><a href="{@docRoot}training/wearables/data-layer/accessing.html">Accessing the Wearable Data Layer</a></dt>
|
||
<dd>This lesson shows you how to create a client to access the Data Layer APIs.</dd>
|
||
|
||
<dt><a href="{@docRoot}training/wearables/data-layer/data-items.html">Syncing Data Items</a></dt>
|
||
<dd>Data items are objects that are stored in a replicated data store that is automatically
|
||
synced from handhelds to wearables.</dd>
|
||
|
||
<dt><a href="{@docRoot}training/wearables/data-layer/assets.html">Transferring Assets</a></dt>
|
||
<dd>Assets are binary blobs of data that you typically use to transfer images or media.</dd>
|
||
|
||
<dt><a href="{@docRoot}training/wearables/data-layer/messages.html">Sending and Receiving Messages</a></dt>
|
||
<dd>Messages are designed for fire-and-forget messages that you can send back and forth
|
||
between the wearable and handheld.</dd>
|
||
|
||
<dt><a href="{@docRoot}training/wearables/data-layer/events.html">Handling Data Layer Events</a></dt>
|
||
<dd>Be notified of changes and events to the data layer.</dd>
|
||
</dl>
|