'Why is my exported DB file not visible to my app running on other tablets?

I've been developing an app that allows for a chain of drink shops to display, sort, and customize their drink menus in a more modern way than stacks of laminated paper menus.

The app is currently deployed, but it became very obvious that a method of sharing the customized .db files is necessary, less an employee resorts to simply duplicating the work of adding recipes to each tablet individually.

I've cobbled together some import/export code that successfully creates a backup file to an external microSD card and it can import that exported .db file successfully. However, when I tried to move the microSD card to my other tablet with the app installed the .db file could not be found.

 protected void importDB() throws IOException {
    try {
        File sd =  new File(myContext.getExternalFilesDir(null).toString() + "recipes.db");
        File data = new File("/data/data/com.raineydesign.reciteateamfuel/databases/recipes.db");

            FileChannel src = new FileInputStream(sd).getChannel();
            FileChannel dst = new FileOutputStream(data).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            Toast.makeText(myContext.getApplicationContext(), "Import Successful!",
                    Toast.LENGTH_SHORT).show();

        } catch (IOException ioException) {
        ioException.printStackTrace();
    }
}

protected void exportDB() throws IOException{
    try {
        File sd = new File(myContext.getExternalFilesDir(null).toString() + "recipes.db");
        File outputFile= new File("/data/data/com.raineydesign.reciteateamfuel/databases/recipes.db");
        Log.e(TAG, String.valueOf(outputFile.exists()));
        InputStream data = new FileInputStream(outputFile) ;

        FileOutputStream outputStream = new FileOutputStream(sd);
        Log.e(TAG, "Databasehelper: Bong");

        byte[] buffer = new byte[1024];
        int length;
        while ((length = data.read(buffer)) > 0) {
            outputStream.write(buffer, 0, length);
        }

        //Close the streams
        data.close();
        outputStream.close();
        Toast.makeText(myContext.getApplicationContext(), "Backup Successful!", Toast.LENGTH_SHORT).show();

    } catch (Exception e) {

        Toast.makeText(myContext.getApplicationContext(), "Backup Failed!", Toast.LENGTH_SHORT)
                .show();

    }
}

I suspect that is issue lies with the use of 'myContext.getExternalFilesDir(null)' as the path for my backup file. However, I went exploring through the microSD files on my desktop and could easily locate the backup file exactly where it should be under android/data/data/com.raineydesign.reciteateamfuel/databases/ so that makes me question my assumption.

If anyone can lend me some advice, I'd be very grateful.



Solution 1:[1]

getExternalFilesDir() has nothing to do with a removable micro sd card.

Better have a look at the second item returned by getExternalFilesDirs()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 blackapps