Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何知道Google Play Games何时成功连接?_Java_Android_Google Api Client - Fatal编程技术网

Java 如何知道Google Play Games何时成功连接?

Java 如何知道Google Play Games何时成功连接?,java,android,google-api-client,Java,Android,Google Api Client,我想在Google Play Games成功连接后开始一项活动。我尝试过在OnConnectiond方法、onConnectionSuspended方法中启动该活动,甚至onConnectionFailed方法也失败了。这一切都不会开始。然后我在onConnected方法中放置了一个断点,并调试了我的应用程序。即使Google Play Games成功连接,该线程也没有挂起。 这些是我连接Google Play游戏的方法 @Override protected void onStart() {

我想在Google Play Games成功连接后开始一项活动。我尝试过在OnConnectiond方法、onConnectionSuspended方法中启动该活动,甚至onConnectionFailed方法也失败了。这一切都不会开始。然后我在onConnected方法中放置了一个断点,并调试了我的应用程序。即使Google Play Games成功连接,该线程也没有挂起。 这些是我连接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();
        }
    }
}
这是我为谷歌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)
您没有设置
连接回调
。以下是您的选择:

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

即使Google Play Games成功连接,线程也没有挂起
您如何知道它已连接?我想这就是问题所在。嗯,我知道它是连接的,但安卓没有。我想让android知道它已连接,这样我就可以开始活动了。谢谢,它成功了!我会在3分钟内接受你的回答。