GoogleApiClient:onConnectionFailed:ConnectionResult{statusCode=RESOLUTION_REQUIRED

GoogleApiClient: onConnectionFailed:ConnectionResult{statusCode=RESOLUTION_REQUIRED

编辑: 它在我的平板电脑和另一台 phone 上运行良好。所以问题与设备有关。有任何想法吗?我已经多次重新安装所有 google 播放相关应用程序但没有成功:/

当我尝试连接 GoogleApiClient 时,我总是得到

onConnectionFailed:ConnectionResult{statusCode=RESOLUTION_REQUIRED, resolution=PendingIntent{13c5b37: android.os.BinderProxy@e07c8a4}, message=null}

当我运行

connectionResult.startResolutionForResult(this, RC_RESOLUTION);

Intent 数据是 null

我完全不知道这里出了什么问题以及 RESOLUTION_REQUIRED 在这种情况下的实际含义。

也许这会有所帮助:如果我对 Drive.API 进行同样的尝试,我会得到一个 SIGN_IN_REQUIRED 错误,这似乎是一个更常见的错误。

如有任何想法,我们将不胜感激!

package com.some.domain.signin;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;

import com.some.domain.activity.MainActivity;
import com.some.domain.application.ApplicationClass;



public class GoogleSignInActivity extends Activity implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks {

    private static final String TAG = "T1_GSignInActivity";
    private static final int RC_RESOLUTION = 9002;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "GoogleSignInActivity");

        setupGoogleClient();
    }

    public static GoogleApiClient googleApiClient;

    public void setupGoogleClient() {
        googleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Games.API).addScope(Games.SCOPE_GAMES)
                .build();

        ApplicationClass.getInstance().setGoogleClient(googleApiClient);
    }


    @Override
    public void onStart() {
        super.onStart();
        googleApiClient.connect();
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RC_RESOLUTION){
            startNextActivity();
        }

    }

    private void startNextActivity() {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }


    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Toast.makeText(this, "Connection failed:\n" + connectionResult.toString(), Toast.LENGTH_LONG ).show();
        try {
            connectionResult.startResolutionForResult(this, RC_RESOLUTION);
        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
        }
        Log.d(TAG, "onConnectionFailed:" + connectionResult);
    }

    @Override
    public void onConnected(@Nullable Bundle bundle) {
        Toast.makeText(this, "Connected.", Toast.LENGTH_LONG ).show();
    }

    @Override
    public void onConnectionSuspended(int i) {
        Toast.makeText(this, "Connection Suspended.", Toast.LENGTH_LONG ).show();
    }
}

请在您的项目

中导入Module项目BaseGameUtils

也在gradle文件中添加

dependencies {
    compile project(':BaseGameUtils')
    // ...
}

Refer link

BaseGameUtils librarie link

好吧,在我苦苦挣扎了两天后,我发现我通过重新安装 google 播放服务和 google 播放商店解决了这个问题。我在两个不同的设备上毫无问题地获得程序 运行 后才意识到这一点...

还要确保以下几点:

Google API: 我将调试和发布证书注册为 Open Auth2 (SHA-1)

Google 玩: 我把"PlayServices"里的游戏连上了我游戏的包名

Google-Services.json: 复制到应用程序文件夹并包含我的所有证书 (SHA-1)

测试人员:我已注册为测试人员