2016-10-05 20 views
1

我正在嘗試將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,給出了消息「應用程序是有問題的播放服務。如果問題仍然存在,請聯繫開發人員尋求幫助。「

我也讀過: <Your App> is having trouble with Google Play services - When using GoogleApiClient, it always trigger onConnectionFailed,但沒有幫助。

我試着在谷歌上查找它,但沒有任何幫助。任何援助將是偉大的!

回答

0

儘量不要在您的點擊onClick()函數中安裝mGoogleApiClient函數。如果您選中此android-demodrive quickstart的mGoogleApiClient被實例化在onResume() lifecycyle:

@Override 
protected void onResume() { 
super.onResume(); 
if (mGoogleApiClient == null) { 
// Create the API client and bind it to an instance variable. 
// We use this instance as the callback for connection and connection 
// failures. 
// Since no account name is passed, the user is prompted to choose. 
mGoogleApiClient = new GoogleApiClient.Builder(this) 
.addApi(Drive.API) 
.addScope(Drive.SCOPE_FILE) 
.addConnectionCallbacks(this) 
.addOnConnectionFailedListener(this) 
.build(); 
} 
// Connect the client. Once connected, the camera is launched. 
mGoogleApiClient.connect(); 
} 

檢查的官方Android Drive API以獲得更多信息。

+0

是的。我已經檢查過。但是這會導致賬戶選擇對話框彈出'onResume()'。我不要那個。我希望僅在用戶想要訪問Google雲端硬盤中的文件時才顯示該對話框。 – Bot

相關問題