I have code for backup create of local sqlite file. It's work fine lower API 28 but above >= 28 it's create issue to create backup file. When I create backup file that time it's create old data file not updated data but display updated data in application.
public void writeBackupOnSD() {
try {
File newFolder = new File(Environment.getExternalStorageDirectory(), "Account_Manager");
if (!newFolder.exists()) {
boolean isCreated = newFolder.mkdir();
Log.d("File", "status" + isCreated);
}
File file = new File(newFolder, backupFileName);//custom file name save on sd
String outFileName = file.getPath();
String inputFileName = getApplicationContext().getFilesDir().getPath()+ "/" + AppConstant.DATABASE_NAME;
if(checkDatabase(inputFileName)) {
FileInputStream myInput = new FileInputStream(new File(inputFileName));
FileOutputStream myOutput = new FileOutputStream(outFileName);
FileChannel src = myInput.getChannel();
FileChannel dst = myOutput.getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
showMessage("Backup successfully!");
}
} catch (Exception e) {
e.printStackTrace();
showMessage("Failed to backup!");
}
}