Android - 从另一台设备访问 Google Drive appdata 文件夹,但同一个应用程序 [英] Android - access Google Drive appdata folder from another device, but same app

查看:22
本文介绍了Android - 从另一台设备访问 Google Drive appdata 文件夹,但同一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用已设置为允许将备份保存到 Google Drive appdata 文件夹.这一切都在同一台设备上运行良好.当我进行备份时,删除应用程序的数据,然后恢复一切正常.

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.

但是,当我尝试在一台设备上备份,然后在另一台设备上安装并尝试恢复时,没有找到任何文件.当我在原始设备上卸载应用程序,在同一设备上重新安装并尝试恢复时也是如此.尽管我在登录 Google Drive 时看到 appdata 文件夹中有文件,但这两种情况都导致找不到文件.

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.

我在某处读到,您必须使用文件的 RESOURCE_ID 而不是 DRIVE_ID 才能在设备之间工作,因为 DRIVE_ID 因设备而异.但是,我看到如何获取 RESOURCE_ID 的唯一方法是使用 driveId.getResourceId(),我无法从其他设备获取正确的 DRIVE_ID.

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:我应该如何从另一个设备/安装创建的 appdata 文件夹中检索正确的文件?

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

推荐答案

我的应用程序中也有一个数据库备份选项.我使用新的 Google Drive Android Api 实现了它,更重要的是,它在一台设备到另一台设备上运行良好.

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. 在向 Google Drive 读取或写入任何内容之前,请调用 requestSync 以确保所有内容都已同步且是最新的(请参阅如何使用它这里).
  2. 使用查询而不是标识符按名称检索文件.由于 Google 云端硬盘允许使用相同名称的多个文件,因此请按日期对查询进行排序并使用最新的.
  3. 为避免创建多个同名备份文件,请使用查询来查找备份文件是否已存在于 Google 云端硬盘中,如果存在,请打开并覆盖它.
  4. 这是我猜你不会喜欢的一点:我建议暂时不要使用 Appfolder....谷歌承认在卸载和重新安装应用程序时可能存在一些同步问题.我尝试在我的应用程序中使用 Appfolder 也没有成功,最后我最终在 Google Drive 中创建了一个普通文件夹.话虽如此,您可以先尝试前三个建议,然后再采用此建议.

我希望这些要点对您的实施有所帮助.如果你还需要什么,尽管说.

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

这篇关于Android - 从另一台设备访问 Google Drive appdata 文件夹,但同一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆