本文介绍了如何将Android上的SQLite数据库备份/还原到Dropbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个使用SQLite数据库的Android应用程序.我正在寻找有关如何在Dropbox等外部服务之间进行数据库备份/还原的想法.我已经做了如下一些解释:

I am currently developing an Android application which makes use of the SQLite database. I am looking for ideas how to backup/restore the database to and from external services such as Dropbox. I have gone through some explanations such as below:

Android备份/恢复:如何备份内部数据库?

在Android中备份/恢复sqlite数据库

这些说明主要是关于本地备份的,但正如我提到的,我想备份到云,例如Dropbox.

These explanation are mainly about backing up locally, but I want to backup to cloud, as I mentioned, something like Dropbox.

请帮助...预先感谢...

Help please...Thanks in advance...

推荐答案

此处使用答案,您可以获得一个.db File对象形式对数据库的引用.

Using the answer here, you can get a reference to your database in the form of a .db File object.

final String inFileName = "/data/data/<your.app.package>/databases/foo.db";
File dbFile = new File(inFileName);

一旦有了这个,就可以使用 Dropbox Sync API .

Once you have this, it's easy to read/write to a user's Dropbox using the Dropbox Sync API.

  • 备份:使用 writeFromExistingFile()将此本地File写入Dropbox目录
  • 还原:使用 getReadStream()来获得一个FileInputStream,该FileInputStream可以写入.db文件所在的相应本地路径.
  • Backup: Use writeFromExistingFile() to write this local File to the Dropbox directory
  • Restore: Use getReadStream() to get a FileInputStream that can write to the appropriate local path where your .db file goes.

这篇关于如何将Android上的SQLite数据库备份/还原到Dropbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:39