You will find your database name in the database adapter if you are new to this.
Note that you can also do this for SharedPreferences, but remember to change Context.MODE_PRIVATE to Context.MODE_MULTI_PROCESS.
SharedPreferences_name should look like this: ExportSP("temp.xml");
String currentPathForSharedPreferences = "/data/"+ context.getPackageName() +"/shared_prefs/"+ SharedPreferences_name;
For export
exportDB("MyDbName"); private void exportDB(String db_name){ File sd = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + File.separator + "Your Backup Folder"+ File.separator ); boolean success = true; if (!sd.exists()) { success = sd.mkdir(); } if (success) { File data = Environment.getDataDirectory(); FileChannel source=null; FileChannel destination=null; String currentDBPath = "/data/"+ context.getPackageName() +"/databases/"+db_name; String backupDBPath = db_name; File currentDB = new File(data, currentDBPath); File backupDB = new File(sd, backupDBPath); try { source = new FileInputStream(currentDB).getChannel(); destination = new FileOutputStream(backupDB).getChannel(); destination.transferFrom(source, 0, source.size()); source.close(); destination.close(); Toast.makeText(this, "Please wait", Toast.LENGTH_SHORT).show(); } catch(IOException e) { e.printStackTrace(); } }}
For import
importDB("MyDbName"); private void importDB(String db_name){ File sd = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + File.separator + "Your Backup Folder"+ File.separator ); File data = Environment.getDataDirectory(); FileChannel source=null; FileChannel destination=null; String backupDBPath = "/data/"+ context.getPackageName() +"/databases/"+db_name; String currentDBPath = db_name; File currentDB = new File(sd, currentDBPath); File backupDB = new File(data, backupDBPath); try { source = new FileInputStream(currentDB).getChannel(); destination = new FileOutputStream(backupDB).getChannel(); destination.transferFrom(source, 0, source.size()); source.close(); destination.close(); Toast.makeText(this, "Please wait", Toast.LENGTH_SHORT).show(); } catch(IOException e) { e.printStackTrace(); } }
ORY May 01 '16 at 17:46 2016-05-01 17:46
source share