Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep modified time of file upon insert into Google Drive API on Android

I am inserting files into Google Drive through the API on Android. Any file that is uploaded takes on the modified time of when it as uploaded, not the original file modified time. If I upload something through the Google Drive App on my desktop, the original modified time of the file is kept.

I have tried using the setModifiedDate() method in the File object, but it doesn't seem to work OR i'm sending the wrong date format possibly? I have tried both of these formats:

2012-08-09T05:34:36-07:00
2012-08-09T05:34:36-0700

Neither seemed to work. Is there an easier way to have it retain the original modified time of the file without having to set it manually (which I can't get to work anyhow)?

The code i am using is the same as the example here: https://developers.google.com/drive/v2/reference/files/insert

Thanks

like image 704
Nek Avatar asked Dec 30 '25 06:12

Nek


1 Answers

I'll answer my own question here.

It turns out I just needed to use setModifiedDate() (which I was already doing) but I needed to NOT set a description using setDescription(). I am not sure if there is a limitation or a bug, but as soon as I removed the description I was setting, then the date I was setting with setModifiedDate() started to work.

I also confirmed the same behaviour with the API Explorer here: https://developers.google.com/drive/v2/reference/files/insert

like image 94
Nek Avatar answered Jan 01 '26 07:01

Nek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!