5

My app is setup to allow backups to be saved to a Google Drive appdata folder. It all works perfectly well on the same device. When I make a backup, delete the app's data, then restore it all works.

However, when I try to backup on one device, then install on another and attempt to restore there are no files found. Same goes for when I uninstall the app on the original device, reinstall it on the same device and attempt to restore. Both cases result in no files being found despite the fact that I see there are files in the appdata folder when I log into Google Drive.

I read somewhere that you must use the RESOURCE_ID instead of the DRIVE_ID of a file for it to work between devices since a DRIVE_ID will be different from device to device. However the only way I've seen how to get the RESOURCE_ID is by using the driveId.getResourceId(), and I can't get the proper DRIVE_ID from another device.

tl;dr: how should I go about retrieving the proper file from the appdata folder that was created by another device/installation?

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Troy Stopera
  • 302
  • 3
  • 15

1 Answers1

11

I have a database backup option in my app as well. I implemented it using the new Google Drive Android Api and what's more important, it works perfectly fine from one device to another.

Here's how I did it and what I recommend:

  1. Before reading or writing anything to Google Drive, call requestSync to make sure everything is synchronized and up to date (see how to use it here).
  2. Retrieve your files by name using a query instead of identifiers. As Google Drive allows multiple files with the same name, order your query by date and use the newest one.
  3. To avoid creating multiple backup files with the same name, use a query to find if the backup file already exists on Google Drive and if it does, open it and overwrite it.
  4. This is the point I guess you won't like: I recommend not using the Appfolder... for the moment. Google has acknowleged there might be some synchronization issues with it when uninstalling and reinstalling the app. I tried to use the Appfolder as well in my app without success and I finally ended up creating an ordinary folder in Google Drive. With that said, you can try the first three recommendations before adopting this one.

I hope these points can help with your implementation. If you need anything else, just tell.

Community
  • 1
  • 1
jmart
  • 2,769
  • 21
  • 36
  • Unfortunately you're probably right. For now I will just use a normal folder and hope the users don't think it's junk and delete it. They shouldn't though since it will have my app's name on it haha. Thanks! – Troy Stopera Jan 15 '15 at 02:37
  • Funny thing, if they do delete it, your GDAA app has plenty of time to bring it back from death, since it will be visible for days. Not even showing the isTrashed() flag on. You can even write to it / create files in it. And don't worry, even if the user empties trash, you'll still see it (until it gets fixed; but since its one-year-anniversary is approaching, it may become a permanent feature :). See http://stackoverflow.com/questions/22515028. – seanpj Jan 15 '15 at 12:30
  • Let me correct it, your Android app actually can't bring it back from death since it has no clue it is gone. So it will happily use it until a few days later... OOPS, now it is gone with all N days of data. – seanpj Jan 15 '15 at 12:35
  • 2
    cant we make folder invisible...so user cant see it – H Raval Sep 15 '16 at 09:16