The solution below was extracted from a SOEN response and does what you want, even though there is plenty of scope for improvements and better portability:
Import
private void importDB() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "<nome do package>"
+ "//databases//" + "<nome da BD>";
String backupDBPath = "<nome ficheiro backup da BD>"; // No SDCard
File backupDB = new File(data, currentDBPath);
File currentDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Importação com sucesso!",
Toast.LENGTH_SHORT).show();
}
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "Importação Falhou!", Toast.LENGTH_SHORT)
.show();
}
}
Export
private void exportDB() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "<nome do package>"
+ "//databases//" + "<nome da BD>";
String backupDBPath = "<destino>";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Backup com sucesso!",
Toast.LENGTH_SHORT).show();
}
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "Backup Falhou!", Toast.LENGTH_SHORT)
.show();
}
}
User Response Credentials @ adefran83 this answer in SOEN.