I have sqlite file in assets and dbflow read it correctly but at runtime I sometimes need to download a new updated sqlite file from internet and place it in certain folder in sdcard so how to update dbflow database by this sqlite file in sdcard to remove data of all tables and add the new data from the file at sdcard to them ?
Asked
Active
Viewed 240 times
-1
-
Simply copy the new database in place of the old one, by maintaining the same location. And restart your app. Your app will now use the new database. – Phantômaxx Nov 28 '17 at 10:04
1 Answers
0
Try the BElow Code. This is a backup I had imported from Application for Restoring Data after Uninstall. Try the code. Hope it Works
NB : PROVIDE READ AND WRITE PERMISSION ON RUNTIME AND IN MANIFEST TOO
private void importDB() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = DOWNLOADEDDATAPATH; //SOURCE
String backupDBPath = "data/" + getContext().getPackageName() + "/databases/FILENAME"; //Destination
File backupDB = new File(sd, currentDBPath); //SOURCE
File currentDB = new File(data, backupDBPath); //Destination
FileChannel src = new FileInputStream(backupDB).getChannel(); //SOURCE
FileChannel dst = new FileOutputStream(currentDB).getChannel(); //Destination
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
} catch (Exception e) {
Log.d("test", e.toString());
}
}

Tomin B Azhakathu
- 2,656
- 1
- 19
- 28