DataApi

A DataItem is
synchronized across all devices in an Android Wear network. It is possible to set data items
while not connected to any nodes. Those data items will be synchronized when the nodes
eventually come online.

Data items are private to the application that created them, and are only accessible by
that application on other nodes. They should generally be small in size, relying on
{@linkplain Asset assets} for the transfer of larger, more persistent data objects such as
images.

DataItem URI format

Each data item is identified by a URI, accessible with
getUri(),
that indicates the item's creator and path. Fully specified URIs follow the following format:

wear://<node_id>/<path>

where <node_id> is the node ID of
the wearable node that created the data item, and <path> is an application-defined
path. This means that given a data item's URI, calling getHost() will
return the creator's node ID.

Concurrency

Concurrent modification of data items from different nodes may result in
inconsistent results. It is recommended that apps are built with some concept of ownership of
data items. Two common patterns are:

Creator owns data items: Data items may be updated only by the original creator
node.

Producer-consumer: One node is responsible for creating a data item, and a second node
is responsible for deleting it, once it has been processed. Data items should have unique
IDs when using this pattern, and data items should not be modified once created.

uri and filterType can be used to filter the data item
changes sent to the listener. For example, if uri and
filterType create a path prefix filter, then only items matching that
prefix will be notified. The uri follows the rules of the <data>
element of <intent-filter>. The path is ignored if a URI host is not specified.
The host should be an Android Wear node ID, or * to match any node. i.e, you should
use:

wear://*/<path>

or

wear://<nodeId>/<path>

Listener events will be called on the main thread, or the handler specified on
client when it was built (using
setHandler(Handler)).

If uri is fully specified, this method will delete at most one data
item. If uri contains a wildcard host, multiple data items may be deleted,
since different nodes may create data items with the same path. See DataApi
for details of the URI format.

The filterType parameter changes the interpretation of
uri. For example, if uri represents a path prefix, all items
matching that prefix will be deleted.

If uri is fully specified, this method will delete at most one data
item. If uri contains a wildcard host, multiple data items may be deleted,
since different nodes may create data items with the same path. See DataApi
for details of the URI format.

Retrieves all data
items matching the provided URI and filter type, from the Android Wear
network.

The URI must contain a path. If uri is fully specified, at most one
data item will be returned. If uri contains a wildcard host, multiple data
items may be returned, since different nodes may create data items with the same path.
See DataApi
for details of the URI format.

Callers must call
release() on the returned buffer when finished processing results.

The filterType parameter changes the interpretation of
uri. For example, if uri represents a path prefix, all items
matching that prefix will be returned.

Retrieves all data
items matching the provided URI, from the Android Wear network.

The URI must contain a path. If uri is fully specified, at most one
data item will be returned. If uri contains a wildcard host, multiple data
items may be returned, since different nodes may create data items with the same path.
See DataApi
for details of the URI format.

Callers must call
release() on the returned buffer when finished processing results.