我正在嘗試將Android的Google Drive API
與我的Android應用程序集成。應用程序在Google Play服務中遇到問題。如果問題仍然存在,請聯繫開發人員尋求幫助
我的大人在Google Developer Console上使用應用程序包名稱和我的機器上的SHA1
創建了一個項目,並生成OAuth 2.0
客戶端ID(我無權訪問該帳戶)。
點擊一個按鈕後,我必須讓用戶訪問Drive上的文件,以便將它們上傳到服務器。
我叫下面的代碼onClick()
:
mGoogleApiClient = new GoogleApiClient.Builder(Activity.this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(Activity.this)
.addOnConnectionFailedListener(Activity.this)
.build();
mGoogleApiClient.connect();
這將調用onConnectionFailed()
回調:
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(TAG, "Connection failed");
if (connectionResult.hasResolution()) {
try {
Log.i(TAG, "Connection failed - Trying again");
connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, message user appropriately
}
} else {
Log.i(TAG, "Connection failed, Code : " + connectionResult.getErrorCode());
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
}
}
連接失敗,再次嘗試。在重試,它會調用onActivityResult()
並嘗試重新連接:
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
if (requestCode == Constants.RESOLVE_CONNECTION_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Log.i(TAG, "Code match");
mGoogleApiClient.connect();
}
}
此時再次連接嘗試失敗,錯誤代碼爲8,給出了消息「應用程序是有問題的播放服務。如果問題仍然存在,請聯繫開發人員尋求幫助。「
我試着在谷歌上查找它,但沒有任何幫助。任何援助將是偉大的!
是的。我已經檢查過。但是這會導致賬戶選擇對話框彈出'onResume()'。我不要那個。我希望僅在用戶想要訪問Google雲端硬盤中的文件時才顯示該對話框。 – Bot