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