Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!