Android/Java:GoogleAppClient将赢得';t连接

Android/Java:GoogleAppClient将赢得';t连接,java,android,google-play-services,google-play-games,Java,Android,Google Play Services,Google Play Games,我使用Android Studio用Java编写了一个Android游戏。现在我想通过谷歌在线交换球员的高分。因此,我在我的onCreate函数中初始化了GoogleAppClient: googleApi = new GoogleApiClient.Builder(FullscreenActivity.this) .addApi(Games.API) .addOnConnectionFailedListener(this)

我使用Android Studio用Java编写了一个Android游戏。现在我想通过谷歌在线交换球员的高分。因此,我在我的
onCreate
函数中初始化了
GoogleAppClient

googleApi = new GoogleApiClient.Builder(FullscreenActivity.this)
                .addApi(Games.API)
                .addOnConnectionFailedListener(this)
                .addConnectionCallbacks(this)
        .build();
其中,
googleApi
是一个公共
GoogleApiClient
变量。 然后是:

@Override
    protected void onStart() {
        super.onStart();
        Log.e("Connected?", String.valueOf(googleApi.isConnected()));
        googleApi.connect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        Log.d("ConnectionFailed", String.valueOf(result));
        if (result.hasResolution()) {
            try {
                // !!!
                result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
            } catch (IntentSender.SendIntentException e) {
                googleApi.connect();
            }
        }
    }

    @Override
    public void onConnected(Bundle bundle) {
        if(!started){
            started = true;
            setContentView(new Game(this));
        }
    }

    @Override
    public void onConnectionSuspended(int i) {
        if(!started){
            started = true;
            this.setContentView(new Game(this));
        }
    }
onConnectionFailed(…)
的输出显示:
D/ConnectionFailed:ConnectionResult{statusCode=SIGN_IN_REQUIRED,resolution=pendingent{2b5bddee:android.os。BinderProxy@7d0328f},message=null}

在我的手机上,Google Play Games登录窗口出现,我也登录了。然后一个旋转的进程圈出现了,它消失了。从未调用
onConnected(…)
函数。 要添加/删除/编辑的内容


这很可能不是重复的,因为我没有找到其他几个内容相同的问题的有效解决方案。

在登录过程中,可能会多次调用
onConnectionFailed
。您看过GitHub中的示例了吗

在示例中,onConnectionFailed实现为:

 public void onConnectionFailed(ConnectionResult connectionResult) {
        Log.d(TAG, "onConnectionFailed");
        if (mIsResolving) {
            // The application is attempting to resolve this connection failure already.
            Log.d(TAG, "onConnectionFailed: already resolving");
            return;
        }

        if (mSignInClicked || mAutoStartSignIn) {
            mSignInClicked = false;
            mAutoStartSignIn = false;

            // Attempt to resolve the connection failure.
            Log.d(TAG, "onConnectionFailed: begin resolution.");
            mIsResolving = resolveConnectionFailure(this, mGoogleApiClient,
                    connectionResult, RC_SIGN_IN, getString(R.string.signin_other_error));
        }

        updateUI();
    }
而resolveConnectionFailure是:

public static boolean resolveConnectionFailure(Activity activity,
                                                   GoogleApiClient client, ConnectionResult result, int requestCode,
                                                   String fallbackErrorMessage) {

        if (result.hasResolution()) {
            try {
                result.startResolutionForResult(activity, requestCode);
                return true;
            } catch (IntentSender.SendIntentException e) {
                // The intent was canceled before it was sent.  Return to the default
                // state and attempt to connect to get an updated ConnectionResult.
                client.connect();
                return false;
            }
        } else {
            // not resolvable... so show an error message
            int errorCode = result.getErrorCode();
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                    activity, requestCode);
            if (dialog != null) {
                dialog.show();
            } else {
                // no built-in dialog: show the fallback error message
                showAlert(activity, fallbackErrorMessage);
            }
            return false;
        }
    }

查看Google Play服务的日志我会先看看,谢谢。谢谢:)这是一个我还没见过的解决方案,让我们看看它是否有效:)