Android Wear - Unexpected error code 16

三世轮回 提交于 2019-12-12 04:55:09

问题


I have an app that uses Android Wear API. To create it I followed the guides here:

https://developer.android.com/training/building-wearables.html

I access the wearable APIs using:

new GoogleApiClient.Builder(context)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .addApi(Wearable.API)
    .build();

In my onConnectionFailedListener, I am getting an error code 16, resulting in a popup to the user saying "GooglePlayServicesUtil﹕ Unexpected error code 16".

@Override
public void onConnectionFailed(ConnectionResult result) {
    if (mResolvingError) {
        // Already attempting to resolve an error.
        return;
    } else if (result.hasResolution()) {
        try {
            mResolvingError = true;
            result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
        } catch (SendIntentException e) {
            // There was an error with the resolution intent. Try again.
            mGoogleApiClient.connect();
        }
    } else {
        // Show dialog using GooglePlayServicesUtil.getErrorDialog()
        showErrorDialog(result.getErrorCode());
        mResolvingError = true;
    }
}

I couldn't find an answer to why this happens in an SO question, so I will add my own.


回答1:


When setting up my Android Wear client, I had missed a wear specific part. See:

https://developer.android.com/google/auth/api-client.html#Starting

"Access the Wearable API"

// 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
    }
    ...
}

Adding this in to my onConnectionFailedListener solved my problem. The Android Wear app was not installed on those devices.



来源:https://stackoverflow.com/questions/29669520/android-wear-unexpected-error-code-16

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!