我对 Google API 和GoogleApiClient
类,所以我跟着本教程 https://developers.google.com/+/mobile/android/sign-in希望能够进行足够的设置来显示排行榜。
目前我已将此代码实施到我的游戏活动中。
public void onConnectionFailed(ConnectionResult arg0) {
Log.d("fes", "error " + arg0.getErrorCode());
if (!isGooglePlayIntentOpen && arg0.hasResolution()) {
try {
isGooglePlayIntentOpen = true;
startIntentSenderForResult(arg0.getResolution()
.getIntentSender(), 10, null, 0, 0, 0);
} catch (SendIntentException ex) {
isGooglePlayIntentOpen = false;
this.getApiClient().connect();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 10) {
isGooglePlayIntentOpen = false;
if (!this.getApiClient().isConnecting() && !this.getApiClient().isConnected()) {
this.getApiClient().connect();
}
}
}
事实上,这确实会弹出一个小意图,显示“连接到 Google Play”,然后选择一个帐户。这正如预期的那样。
然而,每次onConnectionFailed
被调用,错误代码似乎是4.
根据ConnectionResult
, 4 表示需要登录.
是什么赋予了?即使在尝试“登录”多个帐户后,我仍然收到相同的错误代码。我是否需要以某种方式将登录结果传递给我的GoogleApiClient
?
Cheers!