Android 自动将数据库备份到手机存储器和外部存储器
我有备份数据库的功能。谁能帮我写一个自动备份数据库的功能。每一分钟数据库都应该备份到手机存储器或外部存储器Android 自动将数据库备份到手机存储器和外部存储器,android,eclipse,Android,Eclipse,我有备份数据库的功能。谁能帮我写一个自动备份数据库的功能。每一分钟数据库都应该备份到手机存储器或外部存储器 public void backupData() { // date Calendar c = Calendar.getInstance(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); String dbDate = df.format(c.getTime()); p
public void backupData() {
// date
Calendar c = Calendar.getInstance();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String dbDate = df.format(c.getTime());
path = dir.getAbsolutePath();
String currentDBPath = DatabaseHandler.DATABASE_NAME;
String backupDBPath = "247drcare_" + dbDate + ".db";
File currentDB = new File(getDBPath(), currentDBPath);
File backupDB = new File(path, backupDBPath);
if (currentDB.exists()) {
FileChannel src;
try {
src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
// hide other option
if (path == "/storage/sdcard0/247DoctorCare") {
System.out.println(backupDBPath);
System.out.println(settingSuccess);
settingSuccess
.setText("Backup is successfull to your Phone Memory. Backup file Name : "
+ backupDBPath);
} else if (path == "/storage/sdcard1/247DoctorCare") {
settingSuccess
.setText("Backup is successfull to your External Memory. Backup file Name : "
+ backupDBPath);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
Toast.makeText(getApplicationContext(),
"Error in retriving current 247DoctorCare Database.",
Toast.LENGTH_LONG).show();
}
}
提前谢谢。还没有人接电话!。我使用了广播接收器,但仍然没有得到答案。我想调用Alaram管理器中的backUpdatea()函数。请帮助我如何调用此函数。