Sqlite SD-Card. , : -
1) permission Manifest.XML :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
2) Java:
public boolean packupDatabaseFile(){
try {
File sdCardDir = Environment.getExternalStorageDirectory();
File dataDir = Environment.getDataDirectory();
if (sdCard.canWrite()) {
String dbPath = "//data//{your package name}//databases//{your database name}";
String backupDBPath = "{database name}";
File dbFile = new File(dataDir , currentDBPath);
File backupDbFile = new File(sdCardDir , backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(dbFile ).getChannel();
FileChannel dst = new FileOutputStream(backupDbFile ).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
return true;
} catch (Exception e) {
return false;
}
}
Using this Question
source
share