我正在使用Google Drive API for android。這是我現在的代碼。openFileActivityBuilder意圖。如何等待它連接以及如何從中取出文件
public void downloadFromDrive(){
mGoogleApiClient.connect();
IntentSender intentSender = Drive.DriveApi.newOpenFileActivityBuilder().setMimeType(new String[]{"text/plain"}).build(mGoogleApiClient);
try{
startIntentSenderForResult(intentSender,2,null,0,0,0);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
Log.w(TAG, "Unable to send intent", e);
}
}
目前,有2個問題吧。由於沒有結果回調mGoogleClient不能與mGoogleApiClient.connect()連接。有關如何等待實際連接的任何想法?使用isConnected()或onConnect()只會讓我陷入無限循環。我現在只是先用不同的方法連接API客戶端(上傳東西的那個)
如何從IntentSender獲得FileStream?我有關於如何上傳到Google雲端硬盤的代碼,並且我從來不需要用任何方法指定我的OutputStreamWriter。我剛剛創建了一個輸出流,稱爲intentsender,GUI上傳文件沒有問題。
嘗試使用['enableAutoManage(FragmentActivity,GoogleApiClient.OnConnectionFailedListener)'](https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient.Builder#enableAutoManage( android.support.v4.app.FragmentActivity,com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener)),這是管理連接的最簡單的方法,如[documentation](https:// developers)中所述。 google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient)。 – Teyam
另請參閱[訪問Google API](https://developers.google.com/android/guides/api-client)瞭解更多信息。 – Teyam
@Teyam似乎已經解決了這個問題。 – Nephilim