【问题标题】:Android Wear - Unexpected error code 16Android Wear - 意外错误代码 16
【发布时间】:2023-03-13 12:07:01
【问题描述】:

我有一个使用 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:意外错误代码 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 问题中找到为什么会发生这种情况的答案,所以我将添加自己的答案。

【问题讨论】:

    标签: android wear-os


    【解决方案1】:

    在设置我的 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 应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      • 2019-08-01
      • 2016-08-04
      • 2017-11-28
      相关资源
      最近更新 更多