From 4e1620b28f92263677bc6c83a4b2185696e0d0ec Mon Sep 17 00:00:00 2001 From: sreevanis Date: Wed, 13 Jan 2016 12:18:56 -0800 Subject: [PATCH] docs: Documentation for using China variant of the Android Wear SDK. Bug:24924597 Change-Id: I95781d48e354268cca44e463693eaade0c3c469c --- .../wearables/apps/creating-app-china.jd | 157 ++++++++++++++++++ docs/html/training/wearables/apps/creating.jd | 7 + 2 files changed, 164 insertions(+) create mode 100644 docs/html/training/wearables/apps/creating-app-china.jd diff --git a/docs/html/training/wearables/apps/creating-app-china.jd b/docs/html/training/wearables/apps/creating-app-china.jd new file mode 100644 index 0000000000000..d4b3ab74bc844 --- /dev/null +++ b/docs/html/training/wearables/apps/creating-app-china.jd @@ -0,0 +1,157 @@ +page.title=Creating Android Wear Apps for China +parent.title=Training +parent.link=creating.html +page.tags= "wearable", "apps", "china" +page.article=true + +@jd:body + +
+
+

This lesson teaches you to

+
    +
  1. Support Your App on Android Wear for China
  2. +
  3. Use Other Google Play Services APIs
  4. +
+

Dependencies and prerequisites

+
    +
  1. Android 4.3 (API Level 18) or higher on the handset and wearable device
  2. +
+

Downloads

+
    +
    +Standalone Client Library +

    google-play-services-7-8-87.zip

    +
    +
+
+
+ + +

+Handsets sold in China do not have Google Play services preinstalled. For this reason, wearable +apps running on devices in China must communicate with paired handsets through the Android Wear +companion app. To enable you to develop a single APK that works with both Android Wear for China and + Android Wear in the rest of the world, we provide a special variant of the Google Play services +client library.

+ +

+This client library is compatible with Android 4.3 (API level 18) and higher, and you can simply +drop it into your app. You do not need to write any new code. Instead, you change several project +configuration settings, and re-compile your app. +

+ + +

The rest of this page explains how to perform this process.

+ + + +

Support Your App on Android Wear for China

+ +

+

In order to support your wearable app on all handsets, you must download and add the Google Play +Services 7.8.87 client library as a Maven repository in your project, configure your +development project to use it, and re-compile your app. +

+ +

Add the Google Play Services 7.8.87 library

+ +

The Google Play services 7.8.87 client library is distributed as a Maven repository. To add this +repository to your project:

+ +
    +
  1. +Download the client library. +The filename is {@code google-play-services-7-8-87.zip}.
  2. +
  3. Create a local Maven repository by extracting the {@code google-play-services-7-8-87/} directory +from the downloaded zip file, and placing it into the root directory of your project. +
  4. +
  5. In your top-level project {@code build.gradle} file, specify the location of the newly created +local Maven {@code google-play-services-7-8-87} repository. +
  6. +

    +The following example shows how to do so: +

    +
    +allprojects {
    +  repositories {
    +
    +        maven {
    +                url "${rootProject.projectDir}/google-play-services-7-8-87"
    +              }
    +       // ... other repositories may go here ...
    +
    +    }
    +
+

Configure your app to use the library

+

In the {@code build.gradle} file of your mobile module replace the Google Play + services dependency with a reference to the client library from the newly added repository. The + following example shows how to do so: +

+ + +
+dependencies{
+    ...
+    wearApp project(':wear')
+    compile 'com.google.android.gms:play-services-wearable:7.8.87'
+    ...
+    }
+
+

The {@code build.gradle} file of your wear module must also use this version of the +client library, for example: +

+
+dependencies {
+    compile 'com.google.android.support:wearable:1.3.0'
+    compile 'com.google.android.gms:play-services-wearable:7.8.87'
+}
+
+ +

Note: If you are using any other Google Play services APIs in your +wearable app, you must selectively add those Google Play service APIs into your app and explicitly + specify the 7.8.87 version. For example to include the Google location API in your wearable app, + add the following line in your {@code build.gradle} file: +

+
+compile 'com.google.android.gms:play-services-location:7.8.87'
+
+

+

Build the project

+ + +

You can now build +a new version of your app and deploy it to Android handsets globally.

+ + + +

Use Other Google Play services APIs

+ +

+If your app uses Google Play services APIs other than the Wearable API, then your app needs to check +whether these APIs are available to use during runtime and respond appropriately. There are two ways +to check the availability of Google Play service APIs: +

+ +
    +
  1. Use a separate {@code GoogleApiClient} instance for connecting to other APIs. +This interface contains callbacks to alert your app to the success or failure of the connection. +To learn how to handle connection failures, +see Accessing Google APIs.
  2. + +
  3. Use the {@code addApiIfAvailable()} method of +{@code GoogleApiClient.Builder} + +to connect to the required APIs. After the +{@code onConnected()} callback fires, check if each of the requested API is connected correctly +using the + {@code hasConnectedApi()} method. + +
diff --git a/docs/html/training/wearables/apps/creating.jd b/docs/html/training/wearables/apps/creating.jd index f1491e47fd436..db91b672abd66 100644 --- a/docs/html/training/wearables/apps/creating.jd +++ b/docs/html/training/wearables/apps/creating.jd @@ -51,6 +51,13 @@ both your wearable and handheld apps.

To update your SDK with these components, see Get the latest SDK tools.

+

Note: If you plan to make your Wear apps available for China, + you must use the special release version 7.8.87 of the Google Play services client library to handle + communication between handset and wearable. + + For information on how to configure Wear apps for China, see + Creating Android Wear Apps for + China.

Set Up an Android Wear Emulator or Device

We recommend that you develop on real hardware so you can better