Reputation: 1923
I am trying to create a basic wearable app which accepts new bitmaps from the main android application. Unfortunately, when I try to .build() the GoogleApiClient I the connection failed listener is called with an error code 16.
This is the exact error received from the ConnectionFailedListener
03-21 13:36:35.903 3089-3089/com.example.android.wearable.watchface D/Watch Face Config﹕ onConnectionFailed: ConnectionResult{statusCode=unknown status code 16, resolution=null}
App Code:
// create the api client to allow sending information to the wearable
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle connectionHint) {
Log.d(TAG, "onConnected: " + connectionHint);
// Now you can use the Data Layer API
}
@Override
public void onConnectionSuspended(int cause) {
Log.d(TAG, "onConnectionSuspended: " + cause);
}
})
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.d(TAG, "onConnectionFailed: " + result);
}
})
// Request access only to the Wearable API
.addApi(Wearable.API)
.build();
In the wearable app I have a DataListenerService created, but it doesn't matter at the moment because the API is not build correctly.
Thanks for any assistance or comments!!
UPDATE - I changed the emulator device target from Google APIs to Android 5.0.1 and the error changed to:
03-21 14:18:24.620 3025-3025/com.example.android.wearable.watchface D/Watch Face Config﹕ onConnectionFailed: ConnectionResult{statusCode=SERVICE_MISSING, resolution=null}
UPDATE 2 - Found this article and followed the instructions. Then my app failed to compile. After that I went to the SDK manager based on the marked answers suggest and checked Google Play Services (they were not installed). Now the app builds but still gives the SERVICE_MISSING error above.
Upvotes: 1
Views: 2248
Reputation: 28407
You need to have Google Play Services and Android Wear app installed on your device to use the Wearable API. By default, emulators don't have it, so either install it manually, or use a device that has it on board already.
If you're using Genymotion, simply download Google Play Services and drag & drop on the emulator. Then sign in with your Google account and use Play Store to download the Android Wear app.
If you're not using Genymotion, you should start doing it now as it's much faster than standard AVDs.
Just remember, while this will allow your GoogleApiClient
to connect successfully, you'll still have to establish a connection between the emulator and your wearable device (or wearable emulator) if you want to make a real use of the Wearable API. So please refer to other questions on how to create or simulate a bluetooth connection, for example this one.
Edit: official Android emulators are nowadays much faster & have Google Play Services installed out of the box.
Upvotes: 1
Reputation: 1706
Check out this SO question:
Android Wear - Unexpected error code 16
I had a similar problem. The error code is telling you that the Android wear app is not installed. In your onConnectionFailedListener you need to add something like:
// Connection failed listener method for a client that only
// requests access to the Wearable API
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.getErrorCode() == ConnectionResult.API_UNAVAILABLE) {
// The Android Wear app is not installed
}
...
}
From here:
https://developer.android.com/google/auth/api-client.html#Starting
"Access the Wearable API"
Upvotes: 1