diff --git a/docs/html/google/auth/api-client.jd b/docs/html/google/auth/api-client.jd index e33721dcffc08..8f926f571f6d6 100644 --- a/docs/html/google/auth/api-client.jd +++ b/docs/html/google/auth/api-client.jd @@ -99,20 +99,23 @@ GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this) href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient.html">{@code GoogleApiClient} by appending additional calls to -{@code addApi()} and {@code addScope()}.

-Important: To avoid client connection errors on devices that do not have the +Important: If you are adding multiple APIs to a +GoogleApiClient, +you may run into client connection errors on devices that do not have the Android -Wear app installed, use a separate {@code -GoogleApiClient} instance to access only the installed. To avoid connection errors, call the +{@code addApiIfAvailable()} +method and pass in the {@code -Wearable} API. For more information, see Access the Wearable -API.

+Wearable} API to indicate that your client should gracefully handle the missing API. +For more information, see Access the Wearable API.

Before you can begin a connection by calling Access the Wearable API -

On devices that do not have the Android -Wear app installed, connection requests that include the The Wearable API 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. The +{@code Wearable} +API is available on devices running Android 4.3 (API level 18) or higher when a wearable device is +connected. The API is not available under the following conditions: +

+ + + +

Using only the Wearable API

+ +

If your app uses the +{@code Wearable} +API but not other Google APIs, you can add this API by calling the +{@code addApi()} method. The following example shows how to add the +{@code Wearable} +API to your {@code +GoogleApiClient} instance:

+ +
+GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
+    .addApi(Wearable.API)
+    .build();
+
+ +

In situations where the +{@code Wearable} +API is not available, connection requests that include the {@code Wearable} API fail with the -API_UNAVAILABLE error code. If your app uses the {@code -Wearable} API in addition to other Google APIs, use a separate {@code -GoogleApiClient} instance to access the {@code -Wearable} API. This approach enables you to access other Google APIs on devices that are not -paired with a wearable device.

+API_UNAVAILABLE error code.

-

When you use a separate {@code -GoogleApiClient} instance to access only the Wearable API, you can determine -whether the Android -Wear app is installed on the device:

+

+The following example shows how to determine whether the +{@code Wearable} +API is available: +

 // Connection failed listener method for a client that only
@@ -449,15 +477,55 @@ Wear app is installed on the device:

@Override public void onConnectionFailed(ConnectionResult result) { if (result.getErrorCode() == ConnectionResult.API_UNAVAILABLE) { - // The Android Wear app is not installed + // The Wearable API is unavailable } ... }
+

Using the Wearable API with other APIs

+

+If your app uses the +{@code Wearable} +API in addition to other Google APIs, call the +addApiIfAvailable() +method and pass in the +{@code Wearable} +API to indicate that your client should gracefully handle the missing API.

+

The following example shows how to access the +{@code Wearable} +API along with the +{@code Drive} +API:

+ +
+// Create a GoogleApiClient instance
+mGoogleApiClient = new GoogleApiClient.Builder(this)
+        .addApi(Drive.API)
+        .addApiIfAvailable(Wearable.API)
+        .addScope(Drive.SCOPE_FILE)
+        .addConnectionCallbacks(this)
+        .addOnConnectionFailedListener(this)
+        .build();
+
+ +

In the example above, the +{@code GoogleApiClient} +can successfully connect with the Google Drive service without connecting to the +{@code Wearable} +API if it is unavailable. After you connect your +{@code GoogleApiClient} +instance, ensure that the +{@code Wearable} +API is available before making the API calls: +

+ +
+mGoogleApiClient.hasConnectedApi(Wearable.API);
+

Communicate with Google Services

diff --git a/docs/html/training/wearables/data-layer/accessing.jd b/docs/html/training/wearables/data-layer/accessing.jd index 0c0a2d5968e25..482b30c5e0989 100644 --- a/docs/html/training/wearables/data-layer/accessing.jd +++ b/docs/html/training/wearables/data-layer/accessing.jd @@ -61,13 +61,16 @@ GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)

-Important: To avoid client connection errors on devices that do not have the +Important: If you are adding multiple APIs to a +GoogleApiClient, +you may run into client connection errors on devices that do not have the Android -Wear app installed, use a separate {@code -GoogleApiClient} instance to access only the installed. To avoid connection errors, call the +{@code addApiIfAvailable()} +method and pass in the {@code -Wearable} API. For more information, see API to indicate that your client should gracefully handle the missing API. +For more information, see Access the Wearable API.

Before you use the data layer API, start a connection on your client by calling the