Thursday 17 October 2013

Show Databse while testing using device


Method to copy database from data folder to sdcard:

private void Backup(String currentDBPath,String backupDBPath,String Messagetext){
 try 
 {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) 
        {
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);
            if (currentDB.exists())
            {
                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) 
 {
     e.printStackTrace();
 }
}

To call above method, use this code :

String currentDBPath = "//data//com.drc.kwick_ad//databases//"+DBConstants.DB.DATABASE_NAME;
String backupDBPath = DBConstants.DB.DATABASE_NAME;
Backup(currentDBPath,backupDBPath,"Backup Done");

No comments:

Post a Comment