1

I read throughly development documents, sample code and SO related Q&A, it seems the Google Drive Android SDK doesn't include any functionality to automatically sync local folders. Therefore I am going to build one by my own, and here is the strategy:

  • Get files list of local folder
  • Get files list of remote folder
  • Store to status file (json string or database table with file name, parent folder name, location (local or remote), status (synced, uploading, downloading, in queue))
  • Create a sync service to upload or download file if folder is not synced (when any file is not synced status)
  • update status file if any remote change, and start sync service (using drive change event)
  • update status file if any local change, and start sync service (using FileObserve)

During searching, I found the Transfer data using sync adapters lesson but I am not sure if it is useful for this case.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
thanhbinh84
  • 17,876
  • 6
  • 62
  • 69

1 Answers1

2

A couple of pointers

  1. You need to differentiate between a content/media sync vs a metadata sync. Eg. if I rename a file, I only want to sync the new filename, not the file content. Therefore you need two status flags. If you use the V2 API, you can use ETAGs, but they have disappeared in v3. So you might want to use MD5 checksum to detect changes.
  2. You´ll need to deal with sub-folders, either with recursion or by using a universal parent folder.
  3. Guard against sync-loops when you update a local file, sync to a GDrive file, which then shows up as a change on GDrive and triggers a download.
  4. SyncAdapters are your friend, even though they seem hostile at first.
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • Liked your points! I would like to add that the new `WorkManager` API fits very well for such task, so that the sync processing continues also in background. – idish Nov 28 '18 at 22:08