Most visited

Recently visited

Creating Android Wear Apps for China

This lesson teaches you to

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

Dependencies and prerequisites

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

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 google-play-services-7-8-87.zip.
  2. Create a local Maven repository by extracting the google-play-services-7-8-87/ directory from the downloaded zip file, and placing it into the root directory of your project.
  3. In your top-level project build.gradle file, specify the location of the newly created local Maven google-play-services-7-8-87 repository.
  4. 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 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 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 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 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. Use the addApiIfAvailable() method of GoogleApiClient.Builder to connect to the required APIs. After the onConnected() callback fires, check if each of the requested API is connected correctly using the hasConnectedApi() method.

Hooray!