Android 云 - 备份管理器与驱动器

标签 android google-drive-api backup sharedpreferences

我正在开发一个应用程序,我想实现一个功能,可以在相同的用户设备之间共享,比方说,收藏夹、书签等。所以,我想实现类似 iCloud 的东西。

我想到了 2 个可能的想法:Backup Manager 和 Google Drive。 我认为备份管理器是最简单的解决方案,可以满足我的需求,但也许我错了:

Note: The backup service is not designed for synchronizing application data with other clients or saving data that you'd like to access during the normal application lifecycle. You cannot read or write backup data on demand and cannot access it in any way other than through the APIs provided by the Backup Manager.

Note: The backup transport provided by Android Backup Service is not guaranteed to be available on all Android-powered devices that support backup. Some devices might support backup using a different transport, some devices might not support backup at all, and there is no way for your application to know what transport is used on the device.

由于我将此信息存储在 SharedPreferences 中,因此我按照 Google 的建议 (http://developer.android.com/guide/topics/data/backup.html#BackupAgentHelper) 通过扩展 BackupAgentHelper 开始了我的实现。

...each time the user changes some data, your app should call dataChanged(), which adds a backup request to the Backup Manager queue.

因此,每次我更改数据、保存或删除书签时,我都会调用:

BackupManager.dataChanged(C.PROJECT_PATH);

当我的应用程序启动时,我调用:

contentBackupManager.requestRestore(new RestoreObserver() {})

一切都已设置好,还有 AndroidManifest.xml。

不幸的是 requestRestore 正在返回 != 0(错误)和我的 BackupAngent(扩展 BackupAgentHelper)onBackuponRestore 未被调用(onCreate 被调用)。但是,再一次:

A backup request does not result in an immediate call to your onBackup() method. Instead, the Backup Manager waits for an appropriate time, then performs backup for all applications that have requested a backup since the last backup was performed.

这是否意味着我只能在 Google 云端硬盘中找到答案?

最佳答案

你是对的,你不应该为此使用 BackupManager。您将需要使用第三方服务来保存您的确切数据类型。所以你可以:

  • 使用 Google 云端硬盘或 Dropbox 等提供 API 的服务,您可以在其中上传(和下载)任何类型的文件,并以您选择的格式(XML/JSON/二进制)存储数据。这里的好处是:
    • 您不需要用于数据存储的服务器端应用,因此开发工作量更少
    • 用户拥有自己的数据,这对某些用户来说可能很重要
  • 编写一些自定义服务器端代码,为您的应用提供特定的 API。您可以使用 Google App Engine为了这。显然,缺点是增加了开发工作量,如果您有很多用户,应用引擎可能会产生账单。然而,如果你走这条路,你也有很多优势:
    • 您不会浪费用户的云端硬盘或 Dropbox 帐户上的空间,
    • 用户不喜欢在第 3 方应用中输入他们的 Drive/Dropbox 凭据,
    • 您可以使用漂亮的功能,例如 GCM ,
    • 您将数据存储在一个实际的数据库中,因此您可以按照自己的意愿构建它,并且您也拥有它。

你选:)

关于Android 云 - 备份管理器与驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15615196/

相关文章:

c# - 无法在事务内执行备份或还原操作。备份数据库异常终止

security - GitHub 和源代码保护和控制

android - 使用 Espresso 单击 ListView 中的特定复选框

google-drive-api - Google 幻灯片 - 以编程方式获取发布到 Web 链接

java - ArrayMap put方法以奇怪的顺序推送元素

javascript - 如何使用 javascript 将带有 base64 src 的图像保存到 Google 驱动器?

android - Google Drive 的内容提供者

centos - 完整的每周备份和每日增量备份

android - 使用适配器在 Listview 中填充 Listview

android - instr() 函数 SQLITE for Android?