Android - access to the Google Drive application folder from another device, but the same application

My app is set up so that backups are saved in the appdata folder of Google Drive. All this works great on one device. When I make a backup, delete the application data, and then restore it all.

However, when I try to make a backup on one device and then install it on another and try to restore, no files were found. The same thing happens when I uninstall the application on the source device, reinstall it on the same device and try to recover. Both cases lead to the fact that no files were found, despite the fact that I see that there are files in the appdata folder when I enter Google Drive.

I read somewhere that you should use the RESOURCE_ID instead of the DRIVE_ID of the file in order for it to work between devices, since the DRIVE_ID will differ from device to device. However, the only way I saw how to get RESOURCE_ID is using driveId.getResourceId (), and I cannot get the correct DRIVE_ID from another device.

tl; dr: how can I find the correct file from the appdata folder created by another device / installation?

+5
source share
1 answer

I have a database backup option in my application. I implemented it using the new Google Android Android Api, and more importantly, it works great from one device to another.

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

  • Before reading or writing anything to Google Drive, call requestSync to make sure everything is in sync and updated (see how to use it here ).
  • Extract your files by name using a query instead of identifiers. Since Google Drive accepts multiple files with the same name, request your request by date and use the newest.
  • To avoid creating multiple backup files with the same name, use the query to find out if the backup file exists in Google Drive, and if so, open it and overwrite.
  • This is what I think you won’t like: I recommend not using the Appfolder ... for now. Google acknowledged that uninstalling and reinstalling the application may cause some synchronization problems. I tried to use the Appfolder also in my application without success, and finally I created a regular Google Drive folder. With that said, you can try the first three recommendations before accepting this.

I hope that these points will help you in the implementation. If you need anything else, just say it.

+11
source

Source: https://habr.com/ru/post/1210893/


All Articles