I am implementing a solution that saves multiple versions of SQLite database file. Each time the db is saved it is saved with a different file name, I append datetime to make the difference. This works fine and I am able to save multiple version of the SQLite database with different time stamps like this:
/storage/emulated/0/AppName/Backups/auto_backup_2016_Feb_26_07_09 Now what I want is to save this path to database or SharedPreference and when needed I want to be able to restore. To be able to restore the file, first I need to get access again to the file, so I am trying to either get access or recreate the file again using the saved path to that file.
I tried using getAbsolutePath and that did not work and now I am trying Uri. Here is how I save the file
File backupDatabaseFile = new File(backupFolder, Constants.AUTO_BACKUP + "_" + TimeUtils.getDatetimeSuffix(System.currentTimeMillis())); Uri uri = Uri.fromFile(backupDatabaseFile); backupItem.setFilePath(uri.toString()); And here is how I attempt to recreate the saved file so I can restore it:
Uri uri = Uri.parse(backupItem.getFilePath); File backedUpFile = new File(uri.getPath()); And here is where it fails
if (backedUpFile.exists()) { //do something } So how can I can save the path to a file, and then use this path to re-create or access the same file later.