How to backup/restore SQLite database on Android to Dropbox

萝らか妹 提交于 2019-12-30 05:04:17

问题


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 backup/restore: how to backup an internal database?

Backup/restore sqlite db in android

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...


回答1:


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);

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

  • 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.


来源:https://stackoverflow.com/questions/26212460/how-to-backup-restore-sqlite-database-on-android-to-dropbox

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