如何知道 Google Play Games 何时连接成功?
How to know when Google Play Games successfully connects?
我想在 Google Play 游戏连接成功时启动 activity。我试过在 onConnected 方法、onConnectionSuspended 方法甚至 onConnectionFailed 中启动 activity。活动不会开始。然后我在 onConnected 方法中放置了一个断点并调试了我的应用程序。尽管 Google Play Games 已成功连接,但线程并未暂停。
这些是我连接到 Google 玩游戏的方法。
@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)
我想在 Google Play 游戏连接成功时启动 activity。我试过在 onConnected 方法、onConnectionSuspended 方法甚至 onConnectionFailed 中启动 activity。活动不会开始。然后我在 onConnected 方法中放置了一个断点并调试了我的应用程序。尽管 Google Play Games 已成功连接,但线程并未暂停。 这些是我连接到 Google 玩游戏的方法。
@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)