问题
I'm using Drive Android API to sync a file between devices and to hold the latest version on Drive. Since some time ago it started behaving really strange.
To see that a file exists and get it's latest version, I do a Query search by that file name and sorting by modified date descending. It returns the correct datetime when the file was updated:
final SortOrder sortOrder = new SortOrder.Builder()
.addSortDescending(SortableField.MODIFIED_DATE)
.build();
final Query query = new Query.Builder()
.addFilter(Filters.eq(SearchableField.TITLE, "fileName"))
.addFilter(Filters.eq(SearchableField.TRASHED, false))
.setSortOrder(sortOrder)
.build();
Drive.DriveApi.query(apiClient, query)
.setResultCallback(lastModifiedCallback);
But when I query the file contents, it returns some older version of it. I couldn't understand what causes it.
I read the file as follows:
driveId.asDriveFile()
.open(apiClient, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(fileContentsCallback);
The drive contents I read as follows:
final DriveContents driveContents = result.getDriveContents();
final InputStream inputStream = driveContents.getInputStream();
final File newFile = new File("fileName");
final FileOutputStream dest = new FileOutputStream(newFile);
ByteStreams.copy(inputStream, dest);
driveContents.commit(apiClient, null);
Any ideas why it's happening and how to fix it?
I know that the version returned is old, because if I use the Drive application on my device, it returns the correct, latest version of the same file.
来源:https://stackoverflow.com/questions/39183265/google-drive-android-not-returning-latest-version-of-the-file