本文介绍了Android Wear - 意外的错误code 16的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Android Wear API的应用程序。要创建它,我跟着导游在这里:

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

我访问使用可穿戴式的API:

I access the wearable APIs using:

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

在我的 onConnectionFailedListener ,我得到一个错误code 16,结果在弹出的用户说:GooglePlayServicesUtil:意外的错误code 16

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;
    }
}

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

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

推荐答案

在建立我的Andr​​oid Wear的客户,我错过了一个穿特定部分。参见:

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

访问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应用没有安装这些设备上。

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

这篇关于Android Wear - 意外的错误code 16的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 09:56