I’m working on an Android app that uploads files to Google Drive using their API. I’ve run into a problem where the uploaded files are getting new modification timestamps instead of keeping their original ones.
I’ve dealt with this issue before, and it can be tricky. One thing that worked for me was using the ‘setProperties’ method to store the original modification time as a custom property. Then, you can retrieve and display this property instead of relying on the Drive-assigned timestamp. Here’s a rough example:
File fileMetadata = new File();
fileMetadata.setName(“MyFile.txt”);
fileMetadata.setProperties(Collections.singletonMap(“originalModTime”, originalTimestamp));
FileContent mediaContent = new FileContent(“text/plain”, localFile);
This approach doesn’t change the actual modification time in Drive, but it allows you to store and access the original timestamp when needed. You might need to adjust your app’s UI to display this custom property instead of the standard ‘modifiedTime’ field.
I encountered this issue in my project as well. The solution that worked for me was to use the ‘createdTime’ field instead of ‘modifiedTime’. Google Drive API seems to handle ‘createdTime’ more reliably for preserving original timestamps. Here’s the adjusted code:
This approach maintained the original file timestamps in my case. If it doesn’t work, you might need to check your app’s permissions or consider using a different API method for uploads.