Android - access Google Drive appdata folder from another device, but same app

放肆的年华 提交于 2019-11-30 07:32:34
jmart

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!