I read other posts about export data base file in Android but I cant figure out how create or copy this database on Downloader folder.
I use on my Manifest (permissions):
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Activity:
I call this function when I press a button but nothing happens (no exceptions and no file copy or created from currentDBPath)
public void exportDatabase() {
try {
File download_folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File data = Environment.getDataDirectory();
if (download_folder.canWrite()) {
String currentDBPath = "//data//"+getPackageName()+"//databases//"+"YourWords";
String backupDBPath = "YourWords";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(download_folder, 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) {
}
}
Aucun commentaire:
Enregistrer un commentaire