Google Drive Android not returning latest version of the file

与世无争的帅哥 提交于 2019-12-07 13:08:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!