【发布时间】: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 问题中找到为什么会发生这种情况的答案,所以我将添加自己的答案。
【问题讨论】: