【发布时间】:2023-03-10 01:47:01
【问题描述】:
我对 Google API 和 GoogleApiClient 类还有些陌生,所以我关注了 this tutorial,希望能够进行足够的设置以显示排行榜。
目前我已将此代码实现到我的游戏活动中。
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?
干杯!
【问题讨论】:
标签: android google-api google-play-services google-play-games