好的,我正在使用Android工作室創建應用程序,並將其與Google遊戲服務鏈接。但是我遇到了一個問題。連接到Google Play遊戲時出錯
出於某種原因,我無法將我的應用連接到Google遊戲。我相信我所做的一切都是正確的。 這是我目前擁有的代碼:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
這似乎陷入在一個循環,它無法登錄,然後再次嘗試並重新登錄。 這是我得到的logcat的錯誤:
GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED,
resolution=PendingIntent{e154144: [email protected]}}
然而,當我刪除.addApi(Games.API)
和.addScope(Games.SCOPE_GAMES)
遊戲連接到谷歌加完美!
首先,我創建了兩個客戶端ID。一個用於調試,一個用於發佈。 SHA1指紋是正確的。我已檢查並確認兩者匹配。兩者都啓用深度鏈接。我已將gmail添加爲測試人員。 :) 當我檢查谷歌開發者控制檯時,它說已經有81個請求被調用,70個失敗。但是,它不會告訴我哪些失敗,也不知道如何解決它們。我還添加了所有元數據標籤。
請幫忙,問我留下的任何問題。 謝謝 傑克遜·韋爾奇
更新:onActivityResult()
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_RESOLUTION:
retryConnecting();
break;
}
}
這裏是我的onConnectionFailed方法
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// Show a localized error dialog.
GooglePlayServicesUtil.getErrorDialog(
result.getErrorCode(), this, 0, new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
retryConnecting();
}
}).show();
return;
}
// If there is an existing resolution error being displayed or a resolution
// activity has started before, do nothing and wait for resolution
// progress to be completed.
if (mIsInResolution) {
return;
}
mIsInResolution = true;
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
retryConnecting();
}
}
'SIGN_IN_REQUIRED (顯然:用戶需要登錄Google Play遊戲) - 您的「onActivityRes」是什麼? ult()'看起來像? – ianhanniballake
@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){ super.onActivityResult(requestCode,resultCode,data); switch(requestCode){ case REQUEST_CODE_RESOLUTION: retryConnecting(); 休息; } } –
好的,retryConnecting()會做什麼?請編輯您的問題以添加代碼:在評論中閱讀它們非常困難。 – ianhanniballake