GoogleApiClient:onConnectionFailed:ConnectionResult {statusCode = RESOLUTION_REQUIRED

时间:2017-08-25 07:46:22

标签: android google-api-client

编辑:我的平板电脑和另一部手机完全正常。所以这个问题与设备有关。有任何想法吗?我已多次重新安装所有与谷歌相关的应用程序,但没有成功:/

当我尝试连接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();
    }
}

2 个答案:

答案 0 :(得分:0)

请在项目中导入Module项目BaseGameUtils

还添加到gradle文件

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

Refer link

BaseGameUtils librarie link

答案 1 :(得分:0)

好吧,所以在我挣扎了两天后,事实证明我通过重新安装谷歌游戏服务和谷歌游戏商店来解决这个问题。我在没有问题的情况下在两个不同的设备上运行程序之后才意识到这一点......

同时确保以下内容:

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

Google Play:我将“PlayServices”中的游戏与我游戏的包名称联系起来

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

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