[英]Pick any file from users Google Drive and send (Upload) it to my server via Android app
我正在使用Google Drive Android API(GDAA),並且希望使用戶能夠從其Drive中選擇任何文件(Google文檔,表格,圖像,視頻,音頻等)並將其發送到應用服務器。
我已經在網上關注了一些教程以及有關使用GDAA的Google官方文檔。
我也嘗試了以下答案: 通過FileId
獲取Google雲端硬盤文件的內容
但這也不起作用。 我總是將result.getStatus().isSuccess()
設為false
。 我不理解為什么。
以下是我的open()
函數:
private void open() {
DriveFile driveFile = mFileId.asDriveFile();
driveFile.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(driveContentsCallback);
mFileId = null;
}
以下是我得到result.getStatus().isSuccess()
為false
的回調:
/**
* This is Result result handler of Drive contents.
*/
final ResultCallback<DriveApi.DriveContentsResult> driveContentsCallback =
new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
return;
}
// Read from the input stream an print to LOGCAT
DriveContents driveContents = result.getDriveContents();
BufferedReader reader = new BufferedReader(new InputStreamReader(driveContents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
String contentsAsString = builder.toString();
Log.i("ContentAsString", contentsAsString);
// Close file contents
driveContents.discard(mGoogleApiClient);
}
};
現在,我依靠此代碼。 我已經能夠打開Google表格和文檔,但是我需要將它們以及圖像和視頻上傳到我的應用服務器(無需打開文件)。 有沒有辦法可以做到這一點?
我已經閱讀了有關Storage Access Framework(SAF)的信息,它可能允許我從以后訪問Kitkat的Google雲端硬盤文件,但是我的應用支持在JellyBean以及更高版本上運行的設備,因此我要使用GGDA。
我尚未檢查REST API。 我想了解我是否以正確的方式進行操作,或者是否有完全不同的方式來實現自己想要的目標。 如果這是正確的方法,那么哪里出了問題?
任何幫助將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.