How to backup/restore SQLite database on Android to Dropbox

前端 未结 1 1349
感情败类
感情败类 2020-12-30 15:46

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 servi

相关标签:
1条回答
  • 2020-12-30 16:25

    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.
    0 讨论(0)
提交回复
热议问题