首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >onConnectionFailed:ConnectionResult{statusCode=RESOLUTION_REQUIRED :GoogleApiClient

onConnectionFailed:ConnectionResult{statusCode=RESOLUTION_REQUIRED :GoogleApiClient
EN

Stack Overflow用户
提问于 2017-08-25 07:46:22
回答 2查看 588关注 0票数 0

编辑:,它在我的平板电脑和另一部手机上运行得很好。所以这个问题与设备有关。有什么想法吗?我已经多次重新安装了所有与google相关的应用程序,但没有成功:/

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

代码语言:javascript
复制
onConnectionFailed:ConnectionResult{statusCode=RESOLUTION_REQUIRED, resolution=PendingIntent{13c5b37: android.os.BinderProxy@e07c8a4}, message=null}

当我跑的时候

代码语言:javascript
复制
connectionResult.startResolutionForResult(this, RC_RESOLUTION);

Intent数据为null

我在这里非常迷茫,这里出了什么问题,以及RESOLUTION_REQUIRED在这个上下文中的实际含义。

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

任何想法都将不胜感激!

代码语言:javascript
复制
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();
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-27 11:10:04

好吧,在我挣扎了两天之后,我通过重新安装google服务和google商店修复了它。当我在两个不同的设备上运行程序后,我才意识到这一点.

还应确保:

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

Google Play: i将"PlayServices“中的游戏与我的游戏包名连接起来

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

tester :我注册为测试员

票数 0
EN

Stack Overflow用户

发布于 2017-08-25 09:02:56

请在您的项目中导入Module项目BaseGameUtils

还添加了gradle文件

代码语言:javascript
复制
dependencies {
    compile project(':BaseGameUtils')
    // ...
}

参考链接

BaseGameUtils图书馆链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45876641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档