尝试以下代码来检索内容
public void retrieveContents(DriveFile file) {
// [START drive_android_open_file]
Task<DriveContents> openFileTask =
getDriveResourceClient().openFile(file, DriveFile.MODE_READ_ONLY);
// [END drive_android_open_file]
// [START drive_android_read_contents]
openFileTask.continueWithTask(new Continuation<DriveContents, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<DriveContents> task) throws Exception {
DriveContents contents = task.getResult();
// Process contents...
// [START_EXCLUDE]
// [START drive_android_read_as_string]
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(contents.getInputStream()))) {
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line).append("\n");
}
Log.e("result ", builder.toString());
}
// [END drive_android_read_as_string]
// [END_EXCLUDE]
// [START drive_android_discard_contents]
Task<Void> discardTask = MainActivity.this.getDriveResourceClient().discardContents(contents);
// [END drive_android_discard_contents]
return discardTask;
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
// [END drive_android_read_contents]
}