2
我有以下代碼來獲取Google雲端硬盤中文件的DriveContents
。我能夠導入並獲取MS Word,文本文件等的DriveContents
,但是當文件是Google(Google Doc,Google表格等)原生文件時,我無法獲取內容。我的代碼如下:Google雲端硬盤導入Google文檔
selectedFile.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null).setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
public void onResult(DriveApi.DriveContentsResult result) {
try {
if (!result.getStatus().isSuccess()) {
// display an error saying file can't be opened
Log.e(TAG, "Could not get file contents");
return;
}
// DriveContents object contains pointers
// to the actual byte stream
DriveContents contents = result.getDriveContents();
BufferedReader reader = new BufferedReader(new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (Exception e) {
e.printStackTrace();
}
String contentsAsString = builder.toString();
contents.discard(getGoogleApiClient());
Log.i(TAG, contentsAsString);
} catch (Exception e) {
e.printStackTrace();
}
}
});
每當我收到了谷歌格式的文件,它只是返回一個結果是不是成功,並顯示在我的日誌中的錯誤。我怎樣才能獲得這些文件的文件內容?有什麼特別的我應該做的?
我閱讀下列文件:如果