java.lang.Object | ||
↳ | com.google.android.gms.common.api.GoogleApi<com.google.android.gms.wearable.Wearable.WearableOptions> | |
↳ | com.google.android.gms.wearable.DataClient |
Exposes an API for components to read or write data items and assets.
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 assets for the transfer of larger, more persistent data objects such as images.
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.
Some methods, such as getDataItems(Uri)
and addListener(OnDataChangedListener, Uri, int)
, support wildcard node IDs to match data items
with the same path or path prefix created by multiple nodes. A wildcard data item URI has the
following format:
wear://*/<path>See method documentation for details.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
DataClient.FilterType | Data filter types. | ||||||||||
DataClient.GetFdForAssetResponse | Contains a file descriptor for the requested asset. | ||||||||||
DataClient.OnDataChangedListener | Used with addListener(DataClient.OnDataChangedListener) to receive data events. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | ACTION_DATA_CHANGED | Data changed action for use in manifest-based listener filters. | |||||||||
int | FILTER_LITERAL | Filter type for getDataItems(Uri, int) , deleteDataItems(Uri, int) , addListener(OnDataChangedListener, Uri, int) : if this filter is set, the given URI will be
taken as a literal path, and the operation will apply to the matching item only. |
|||||||||
int | FILTER_PREFIX | Filter type for getDataItems(Uri, int) , deleteDataItems(Uri, int) , addListener(OnDataChangedListener, Uri, int) : if this filter is set, the given URI will be
taken as a path prefix, and the operation will apply to all matching items. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Registers a listener to receive data item changed and deleted events.
| |||||||||||
Registers a listener to receive data item changed and deleted events.
| |||||||||||
Removes all specified
data items from the Android Wear network. | |||||||||||
Removes all specified
data items from the Android Wear network. | |||||||||||
Retrieves a single
DataItem from the Android Wear network. | |||||||||||
Retrieves all
data items matching the provided URI and filter type, from the
Android Wear network. | |||||||||||
Retrieves all
data items from the Android Wear network. | |||||||||||
Retrieves all
data items matching the provided URI, from the Android Wear
network. | |||||||||||
Retrieves a
ParcelFileDescriptor pointing at the bytes of an asset. | |||||||||||
Retrieves a
ParcelFileDescriptor pointing at the bytes of an asset. | |||||||||||
Adds a
DataItem to the Android Wear network. | |||||||||||
Removes a listener which was previously added through
addListener(OnDataChangedListener) or addListener(OnDataChangedListener, Uri, int) . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Data changed action for use in manifest-based listener filters.
See also:
Filter type for getDataItems(Uri, int)
, deleteDataItems(Uri, int)
, addListener(OnDataChangedListener, Uri, int)
: if this filter is set, the given URI will be
taken as a literal path, and the operation will apply to the matching item only.
Filter type for getDataItems(Uri, int)
, deleteDataItems(Uri, int)
, addListener(OnDataChangedListener, Uri, int)
: if this filter is set, the given URI will be
taken as a path prefix, and the operation will apply to all matching items.
Registers a listener to receive data item changed and deleted events. This call should be
balanced with a call to removeListener(OnDataChangedListener)
, to avoid leaking
resources.
Listeners will be called on the main thread, or the looper set in Wearable.WearableOptions
.
Parameters | |
---|---|
listener |
DataClient.OnDataChangedListener |
Returns | |
---|---|
Task<Void> |
Registers a listener to receive data item changed and deleted events. This call should be
balanced with a call to removeListener(OnDataChangedListener)
, to avoid leaking
resources.
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>
Listeners will be called on the main thread, or the looper set in Wearable.WearableOptions
.
Callers wishing to be notified of events in the background should use WearableListenerService
.
Parameters | |
---|---|
listener |
DataClient.OnDataChangedListener |
uri |
Uri |
filterType |
int |
Returns | |
---|---|
Task<Void> |
Removes all specified data items
from the Android Wear network.
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 DataClient
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.
Parameters | |
---|---|
uri |
Uri |
filterType |
int |
Returns | |
---|---|
Task<Integer> |
the number of deleted items. |
Removes all specified data items
from the Android Wear network.
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 DataClient
for details of the URI format.
Parameters | |
---|---|
uri |
Uri |
Returns | |
---|---|
Task<Integer> |
the number of deleted items. |
Retrieves a single DataItem
from the Android Wear network. A fully qualified URI must
be specified. The URI's host must be the ID of the node that created the item.
See DataClient
for details of the URI format.
Parameters | |
---|---|
uri |
Uri |
Returns | |
---|---|
Task<DataItem> |
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 DataClient
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.
Parameters | |
---|---|
uri |
Uri |
filterType |
int |
Returns | |
---|---|
Task<DataItemBuffer> |
Retrieves all data items
from the Android Wear network.
Callers must call release()
on the returned buffer when finished
processing results.
Returns | |
---|---|
Task<DataItemBuffer> |
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 DataClient
for
details of the URI format.
Callers must call release()
on the returned buffer when finished
processing results.
Parameters | |
---|---|
uri |
Uri |
Returns | |
---|---|
Task<DataItemBuffer> |
Retrieves a ParcelFileDescriptor
pointing at the bytes of an asset. Only assets
previously stored in a DataItem
may be retrieved.
Parameters | |
---|---|
asset |
DataItemAsset |
Returns | |
---|---|
Task<DataClient.GetFdForAssetResponse> |
Retrieves a ParcelFileDescriptor
pointing at the bytes of an asset. Only assets
previously stored in a DataItem
may be retrieved.
Parameters | |
---|---|
asset |
Asset |
Returns | |
---|---|
Task<DataClient.GetFdForAssetResponse> |
Removes a listener which was previously added through addListener(OnDataChangedListener)
or addListener(OnDataChangedListener, Uri, int)
.
Parameters | |
---|---|
listener |
DataClient.OnDataChangedListener |
Returns | |
---|---|
Task<Boolean> |