I have backed up the sqlite db file to storage using the code below But from Android 11, I have to use mediastore, but I don't know how. Can I back up sqlite db using mediastore?
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + packageName + "//databases//" + dbName + ".db";
String backupDBPath = "//" + saveFolder + "//" + dbName + ".db"; // 백업 위치
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
Log.i("sinwhod","currentDB = " + currentDB);
Log.i("sinwhod","backupDB = " + backupDB);
Log.i("sinwhod","backupDBPath = " + backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
} catch (Exception e) {
}