融云聊天记录备份到本地。

思路:
1、获取融云聊天记录本地数据库
2、将本地数据库复制一份到sd卡
3、将备份到sd卡的数据库与融云本地数据库合并。

1、经过查找资料后发现融云的聊天记录数据库保存地址为:
/data/data/包名/files/{app融云生产key}/{用户useid}/storage

2、复制数据库文件到sd卡:
FileUtils.copyFile(dbPath, SDPath);

3、连接sqlite数据库合并两个数据库的数据。

SQLiteDatabase newdb = SQLiteDatabase.openOrCreateDatabase(dbPath, null);
        try {
            newdb.execSQL("ATTACH DATABASE ? AS 'storage_team'", new String[]{SDPath});
            newdb.execSQL("INSERT OR IGNORE INTO RCT_MESSAGE SELECT * FROM storage_team.RCT_MESSAGE order by send_time");
            newdb.execSQL("INSERT OR IGNORE INTO RCT_CONVERSATION SELECT * FROM storage_team.RCT_CONVERSATION");
            newdb.execSQL("INSERT OR IGNORE INTO RCT_USER SELECT * FROM storage_team.RCT_USER");

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

你可能感兴趣的:(android)