From eff209d2c40221d2f9be2fd6b0c9cde51dd5362b Mon Sep 17 00:00:00 2001
From: Ricardo Cervera
dependencies
for the latest version of
-play-services
. For example:
+ play-services
.
+ For example, for mobile modules:
apply plugin: 'android' ... @@ -70,7 +71,16 @@ dependencies { compile 'com.google.android.gms:play-services:6.1.+' }-
Be sure you update this version number each time Google Play services is updated.
+For wearable modules:
++apply plugin: 'android' +... + +dependencies { + compile 'com.google.android.gms:play-services-wearable:6.1.+' +} ++
Be sure you update this version number each time Google Play services is updated.
To call the data layer API, create an instance of +
To call the Data Layer API, create an instance of
GoogleApiClient
,
the main entry point for any of the Google Play services APIs.
Before you use the data layer API, start a connection on your client by calling the
-connect()
+
+connect()
method, as described in
-Accessing Google Play services APIs.
-When the system invokes the onConnected()
callback for your client, you're ready
-to use the data layer API.
onConnected()
callback for your client, you're ready to use the Data Layer API.
diff --git a/docs/html/training/wearables/data-layer/assets.jd b/docs/html/training/wearables/data-layer/assets.jd
index 5dc11cb..719ccbc 100644
--- a/docs/html/training/wearables/data-layer/assets.jd
+++ b/docs/html/training/wearables/data-layer/assets.jd
@@ -16,18 +16,18 @@ page.title=Transferring Assets
To send large blobs of binary data over the Bluetooth transport, such as images, attach an
-Asset to a
+Asset
to a
data item and the put the data item into the replicated data store.
Assets automatically handle caching of data to prevent retransmission and conserve Bluetooth bandwidth. A common pattern is for a handheld app to download an image, shrink it to an appropriate size -for display on the wearable, and transmit it to the wearable app as an Asset. The following examples -demonstrates this pattern. +for display on the wearable, and transmit it to the wearable app as an asset. The following examples +demonstrate this pattern.
-Note: Although the size of data items are limited to 100KB, -assets can be as large as desired. However, transferring large assets affect the +
Note: Although the size of data items is limited to 100KB, +assets can be as large as desired. However, transferring large assets affects the user experience in many cases, so test your apps to ensure that they perform well if you're transferring large assets.
@@ -49,7 +49,6 @@ private static Asset createAssetFromBitmap(Bitmap bitmap) {
When you have an asset, attach it to a data item with the putAsset()
method in
-
DataMap
or
PutDataRequest
@@ -77,12 +76,13 @@ PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi
.putDataItem(mGoogleApiClient, request);
+
When an asset is created, you probably want to read and extract it on other side of the connection. Here's an example of how to implement the -callback to detect an asset change and extract the Asset: +callback to detect an asset change and extract the asset:
diff --git a/docs/html/training/wearables/data-layer/data-items.jd b/docs/html/training/wearables/data-layer/data-items.jd index f843bb6..12babbf 100644 --- a/docs/html/training/wearables/data-layer/data-items.jd +++ b/docs/html/training/wearables/data-layer/data-items.jd @@ -15,9 +15,9 @@ page.title=Syncing Data Items-A
DataItem
+ADataItem
defines the data interface that the system uses to synchronize data between handhelds -and wearables. ADataItem
generally +and wearables. ADataItem
generally consists of the following items:
-You normally don't implement DataItem
+You normally don't implement DataItem
directly. Instead, you:
PutDataRequest
object,
specifying a string path to uniquely identify the item.
setData()
to set the payload.
DataApi.putDataItem()
to request the system to create the data item.
When possible, use the DataMap
class.
@@ -67,7 +68,7 @@ object, setting the path of the data item.
Note: The path string is a unique identifier for the data item that allows you to access it from either side of the connection. The path must begin with a forward slash. If you're using hierarchical data in your -app, you should create a path scheme that matches the structure of the data. +app, you should create a path scheme that matches the structure of the data.
DataApi.putDataItem()
to request the system to create the data item.
Note: If the handset and wearable devices are disconnected, - the data is buffered and and synced when the connection is re-established. + the data is buffered and synced when the connection is re-established.
The following example shows how to create a data map, set data on it, and create it:
+The following example shows how to create a data map and put data on it:
PutDataMapRequest dataMap = PutDataMapRequest.create("/count"); @@ -103,7 +104,7 @@ to be notified of any changes on the other side of the connection. You can do this by implementing a listener for data item events.For example, here's what a typical callback looks like to carry out certain actions -when data changes.
+when data changes:@Override @@ -120,5 +121,6 @@ public void onDataChanged(DataEventBuffer dataEvents) {This is just a snippet that requires more implementation details. Learn about how to implement a full listener service or activity in -Listening for Data Layer Events. +Listen for Data Layer +Events.
\ No newline at end of file diff --git a/docs/html/training/wearables/data-layer/events.jd b/docs/html/training/wearables/data-layer/events.jd index 9196a2c..6a3949a 100644 --- a/docs/html/training/wearables/data-layer/events.jd +++ b/docs/html/training/wearables/data-layer/events.jd @@ -14,14 +14,14 @@ page.title=Handling Data Layer Events -When you make calls with the data layer, you can receive the status +
When you make calls to the Data Layer API, you can receive the status of the call when it completes as well as listen for any changes that the call ends up making with listeners.
Wait for the Status of Data Layer Calls
-You'll notice that calls to the data layer API sometimes return a +
You'll notice that calls to the Data Layer API sometimes return a
-PendingResult
, such asputDataItem()
. @@ -33,9 +33,9 @@ after the operation completes, so the lets you wait for the result status, either synchronously or asynchronously.Asynchronously waiting
-If your code is running on the main UI thread, do not making blocking calls -to the data layer API. You can run the calls asynchronously by adding a callback +
Asynchronous calls
+If your code is running on the main UI thread, do not make blocking calls +to the Data Layer API. You can run the calls asynchronously by adding a callback method to the
PendingResult
object, which fires when the operation is completed:@@ -49,12 +49,14 @@ pendingResult.setResultCallback(new ResultCallback<DataItemResult>() { });-Synchronously waiting
+Synchronous calls
If your code is running on a separate handler thread in a background service (which is the case in a
@@ -82,14 +84,14 @@ are created, messages are received, or when the wearable and handset are connect -WearableListenerService
), it's fine for the calls to block. In this case, you can callawait()
-on the PendingResult object, which will block until the request has completed, and return a Result +on thePendingResult
+object, which blocks until the request completes and returns a +Result
object:With both these options, you override any of the data event callbacks that you care about -handling in your implementation.
+With both these options, you override the data event callback methods for the events you +are interested in handling.
With a WearableListenerService
You typically create instances of this service in both your wearable and handheld apps. If you -don't care about data events in one of these apps, then you don't need to implement this +are not interested in data events in one of these apps, then you don't need to implement this service in that particular app.
For example, you can have a handheld app that sets and gets data item objects and a wearable app @@ -107,8 +109,9 @@ triggers this callback on both sides. - A message sent from one side of a connection triggers this callback on the other side of the connection.
onPeerConnected()
and onPeerDisconnected()
-
- Called when connection with the handheld or wearable is connected or disconnected.
- Changes in connection state on one side of the connection triggers these callbacks on both sides of the connection.
+ Called when the connection with the handheld or wearable is connected or disconnected.
+ Changes in connection state on one side of the connection trigger these callbacks on both sides
+ of the connection.
WearableListenerService
.
onDataChanged()
.
+ onDataChanged()
.
WearableListenerService
.
@@ -165,7 +168,7 @@ public class DataLayerListenerService extends WearableListenerService {
// Get the node id from the host value of the URI
String nodeId = uri.getHost();
- // Set the data of the message to be the bytes of the URI.
+ // Set the data of the message to be the bytes of the URI
byte[] payload = uri.toString().getBytes();
// Send the RPC
@@ -189,7 +192,8 @@ public class DataLayerListenerService extends WearableListenerService {
In order to deliver callbacks to your application for data layer events, Google Play services +
+To deliver callbacks to your application for data layer events, Google Play services
binds to your WearableListenerService
,
and calls your callbacks via IPC. This has the consequence
that your callbacks inherit the permissions of the calling process.
GoogleApiClient
-to work with the data layer API.
+to work with the Data Layer API.
connect()
to connect the client to Google Play services.
-Unlike data items, there is no syncing between the handheld and wearable apps. +Unlike with data items, there is no syncing between the handheld and wearable apps. Messages are a one-way communication mechanism that's good for remote procedure calls (RPC), -such as sending a message to the wearable -to start an activity. You can also use messages in request/response model -where one side of the connection sends a message, does some work, -and sends back a response message.
+such as sending a message to the wearable to start an activity.The following example shows how to send a message that indicates to the other -side of the connect to start an activity. -This call is made synchronously, which blocks until the message -is received or when the request times out: -
+side of the connection to start an activity. +This call is synchronous and blocks processing until the message is received or until the request +times out:Note: Read more about asynchronous and synchronous calls to Google Play services and when to use each in @@ -61,7 +57,7 @@ send messages to:
private Collection<String> getNodes() { - HashSet <String>results= new HashSet<String>(); + HashSet <String>results = new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await(); for (Node node : nodes.getNodes()) { @@ -71,14 +67,17 @@ private Collection<String> getNodes() { }-
-
-To be notified of received messages, you implement a listener for message events.
-This example shows how you might do this by checking the START_ACTIVITY_PATH
-that the previous example used to send the message. If this condition is true
,
-a specific activity is started.
+To be notified of received messages, you implement the
+
+MessageListener
interface to provide a listener for message events. Then you register your
+listener with the
+
+MessageApi.addListener()
method. This example shows how you might implement the listener
+to check the START_ACTIVITY_PATH
that the previous example used to send the message.
+If this condition is true
, a specific activity is started.
@@ -95,5 +94,6 @@ public void onMessageReceived(MessageEvent messageEvent) {This is just a snippet that requires more implementation details. Learn about how to implement a full listener service or activity in -Listening for Data Layer Events. +Listening for Data Layer +Events.
\ No newline at end of file -- cgit v1.1