Android Wear - 意外错误代码16

时间:2015-04-16 08:39:30

标签: android wear-os

我有一个使用Android Wear API的应用。为了创建它,我按照这里的指南进行了操作:

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

我使用以下方式访问可穿戴API:

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

在我的onConnectionFailedListener中,我收到错误代码16,导致用户弹出“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;
    }
}

我找不到为什么在SO问题中发生这种情况的答案,所以我将添加自己的答案。

1 个答案:

答案 0 :(得分:0)

在设置我的Android Wear客户端时,我错过了一个特定的磨损部件。参见:

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

“访问可穿戴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
    }
    ...
}

将此添加到我的onConnectionFailedListener解决了我的问题。这些设备上没有安装Android Wear应用程序。