java - 如何知道 Google Play 游戏何时连接成功?

标签 java android google-api-client

我想在 Google Play 游戏连接成功后开始一项 Activity 。我尝试过在 onConnected 方法、onConnectionSuspished 方法,甚至 onConnectionFailed 中启动 Activity 。 Activity 无法开始。然后,我在 onConnected 方法中放置了一个断点并调试了我的应用程序。即使 Google Play 游戏连接成功,该线程也没有暂停。 这些是我连接 Google Play 游戏的方法。

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}
@Override
public void onConnected(@Nullable Bundle bundle) {

}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()){
        try{
            connectionResult.startResolutionForResult(this, 0);
        }catch (IntentSender.SendIntentException e){
            mGoogleApiClient.connect();
        }
    }
}

这是我的 Google Api 客户端代码。

mGoogleApiClient = new GoogleApiClient.Builder(this).addOnConnectionFailedListener(this)
            .addApi(Plus.API, Plus.PlusOptions.builder().build()).addScope(Plus.SCOPE_PLUS_LOGIN)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES).build();

我做错了什么吗?我错过了什么吗?谢谢。

最佳答案

罪魁祸首就在这里

mGoogleApiClient = new GoogleApiClient.Builder(this).addOnConnectionFailedListener(this)

您没有设置ConnectionCallbacks。以下是您的选择:

mGoogleApiClient = new GoogleApiClient.Builder(this, this, this)
// or
mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)

Reference

关于java - 如何知道 Google Play 游戏何时连接成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45040617/

相关文章:

java - 为什么我不能像导入类后那样在 java.io.PrintStream 中使用 print() 或 println() 方法?

java - joda Chronology 和 DateTimeZone 之间有什么区别?

android - 如何制作特殊区域以调用触摸事件?

php - Google Youtube API 插入评论总是返回错误响应 403 - "Insufficient Permission"- 域 "global"

python - 使用 python 为 Google Play Developer API 使用 oauth2 授权服务帐户

php - 在 Laravel 5 中使用 Google Drive Api

java - 我收到 Auth Error : Authentication failure due to [java. io.FileNotFoundException: while implementation pusher-js in Android studio

java - 为什么在 eclipse 中出现 NoClassDefFound 错误是可以接受的?解决办法是什么?

启动时的 Android pin Activity

java - 相机 Intent 回调后Android图像调整大小