Hello I have this code
public void onbtnExportDBToPCClick(View view){
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
Toast.makeText(getBaseContext(), data.toString(),
Toast.LENGTH_LONG).show();
if (sd.canWrite()) {
String currentDBPath = "//"+data+"//" + getPackageName() + "//databases//"+"cDataBase.db";
String backupDBPath = "//backupcDataBase.db";
File currentDB = new File(currentDBPath);
File backupDB = new File(sd, backupDBPath);
Toast.makeText(getBaseContext(), currentDBPath.toString(),
Toast.LENGTH_LONG).show();
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();
Toast.makeText(getBaseContext(), backupDB.toString(),
Toast.LENGTH_LONG).show();
}
}
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG)
.show();
}
I have set permitions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" > </uses-permission>
but code stops at if (sd.canWrite()) it does not go further. I don't know what is the problem. What else should I have to set?
Aucun commentaire:
Enregistrer un commentaire