我为应用程序设置了 Google Plus 登录,使用 GoogleApiClient
进行连接。
每当第一次安装应用程序并尝试通过 GoogleApiClient
进行连接时,它永远无法成功,总是最终在 onConnectionFailed
处结束,其中 result
包含:
ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{4130e760: android.os.BinderProxy@4130e700}}
但是当第二次登录时,它被称为并且成功连接,onConnected
也会被触发。为什么会这样?有没有可能在第一次尝试时就成功连接?
我的Builder
参数有问题吗?
public void connectGoogleApi() {
mGoogleApiClient = new GoogleApiClient.Builder(mainAppContext).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build();
mGoogleApiClient.connect();
}
public void onConnectionFailed(ConnectionResult result) {
if (!result.hasResolution()) {
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show();
return;
}
if (!mIntentInProgress) {
// Store the ConnectionResult for later usage
mConnectionResult = result;
resolveSignInError();
}
}