0

my problem is the following: I have correctly moved the SQlite database on the local SD, but the file is not visible both from the device and the PC via USB connection. The app does not raise any error. Here is the method that performs the copy: private void exportDB(){

    DBHelper db = DBHelper.getInstance(this);
    String DBName = db.getDBName();
    File dbPath = this.getDatabasePath(DBName);
    String DBPath = dbPath.getAbsolutePath();
    //Toast.makeText(this, "DB Path : " + DBPath , Toast.LENGTH_LONG).show();


    File sd = Environment.getExternalStorageDirectory();
    File data = Environment.getDataDirectory();
    FileChannel source=null;
    FileChannel destination=null;
    String currentDBPath = DBPath;
    String backupDBPath = "Download/"+DBName;
    File currentDB = new File(currentDBPath);
    File backupDB = new File(sd, backupDBPath);
    try {
        source = new FileInputStream(currentDB).getChannel();
        destination = new FileOutputStream(backupDB).getChannel();
        destination.transferFrom(source, 0, source.size());
        source.close();

        destination.close();
        Toast.makeText(this, "DB Exported!", Toast.LENGTH_LONG).show();
    } catch(FileNotFoundException e) {
        e.printStackTrace();
    }catch(IOException e) {
        e.printStackTrace();
    }


}
user401574
  • 21
  • 1
  • https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl – CommonsWare Nov 16 '17 at 16:38
  • May it be a privileges problem? it is the same beahviour that I had with the original destination of the file in the internal storage. – user401574 Nov 16 '17 at 16:40
  • `I have correctly moved the SQlite database on the local SD`. Your code looks correct but it would not have moved but copied the db file. And not to SD card but to external memory. You will see the file on your pc after reboot of your device. – greenapps Nov 16 '17 at 18:06
  • `Toast.makeText(this, "DB Exported!", Toast.LENGTH_LONG).show();`. Did you see that toast? – greenapps Nov 16 '17 at 18:07
  • Why dont you have Toasts in those two catch blocks? You should inform the user of your app when there are exceptions. – greenapps Nov 16 '17 at 18:09

1 Answers1

0

for transferting DB, I think it may achievable in rooted device.