Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda