我使用Android Studio在Java中編寫了Android遊戲。現在我想通過GoogleApi在線交換球員的高分。所以,我在onCreate
函數初始化GoogleApiClient
:Android/Java:GoogleApiClient不會連接
googleApi = new GoogleApiClient.Builder(FullscreenActivity.this)
.addApi(Games.API)
.addOnConnectionFailedListener(this)
.addConnectionCallbacks(this)
.build();
凡googleApi
是公共GoogleApiClient
變量。 再就是:
@Override
protected void onStart() {
super.onStart();
Log.e("Connected?", String.valueOf(googleApi.isConnected()));
googleApi.connect();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.d("ConnectionFailed", String.valueOf(result));
if (result.hasResolution()) {
try {
// !!!
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (IntentSender.SendIntentException e) {
googleApi.connect();
}
}
}
@Override
public void onConnected(Bundle bundle) {
if(!started){
started = true;
setContentView(new Game(this));
}
}
@Override
public void onConnectionSuspended(int i) {
if(!started){
started = true;
this.setContentView(new Game(this));
}
}
的onConnectionFailed(...)
輸出說道:D/ConnectionFailed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{2b5bddee: [email protected]}, message=null}
我的手機在谷歌玩遊戲登錄窗口出現了,並且我登錄然後旋轉進步圈子被顯示,並消失了。功能從來沒有被調用過。 要添加/刪除/編輯什麼?
這很可能不是重複的,因爲我沒有找到其他幾個問題的工作解決方案,內容相同。
檢查谷歌播放服務的日誌https://developers.google.com/games/services/ android/logging – danieljohngomez
我會先看看,謝謝。 – Unknown