Find Sqlite Database on Android

Asked

Viewed 2,528 times

1

Next, I’m creating an application for Android, where I use a local Sqlite bank, never gave any kind of problem of registration or database query, so I never had to take the bank direct in the emulator, but now I’m in need, the problem is, I can’t locate this database, it’s created, it has data, I just can’t locate it. I use Android Studio, I’ve looked in Android Device Monitor, but I can’t open the folder "data", as it is empty. The strange thing is that if I try to create a "date/date" folder it says that the file already exists. How can I recover this database?

  • Only through the application itself. This directory is protected and can only be accessed by the creator. You will need to "copy" that file to a public directory before being able to find it

  • But does Emulator not have permissions for this? If not how do I copy the database to a public folder.

  • 1

    I don’t think so. The OS is the manager, not the platform (emulator). As I said, to copy you need to code in the app itself. Ex.: When you click a certain button, copy the database file to the "Downloads folder".

2 answers

4


The reason why subdirectories do not appear in the folder Data is the adb not having permission to read its contents.

Use the Device File Explorer.

You can open it through View > Windows Tool > Device File Explorer or by clicking the existing button on the lower right side of Android Studio.

inserir a descrição da imagem aqui

You can interact with the content by right-clicking to create a new one, save the selected file or folder to your pc, delete or sync.

Notes:

  • Requires Android Studio 3.0 or higher
  • The contents of the folder Data is only visible if the device is an emulator.
  • There is no such option in my Android Studio

  • What is the version of Android Studio that uses?

  • 2.3.3, I will update

  • Thanks, it worked out!

4

In case you do not find the file through the "Device File Explorer" window, you can use the code below:

try {

    /* Captura o arquivo original */
    File src = new File(Environment.getDataDirectory(), "//data//".concat(getPackageName()).concat("//databases//SEU-BANCO.db"));

    /* Captura o caminho do arquivo de destino */
    File dst = new File(Environment.getExternalStorageDirectory().getPath().concat("/SEU-BANCO-BACKUP.db"));

    /* Cria o arquivo de destino */
    dst.createNewFile();

    /* Abre o arquivo original e o de destino para leitura e escrita, respectivamente */
    FileInputStream inputStream = new FileInputStream(src);
    FileOutputStream outputStream = new FileOutputStream(dst);
    int b = 0;

    /* Ler o conteúdo em byte do arquivo original e escreve no arquivo de destino */
    while ((b = inputStream.read()) != -1) {
        outputStream.write(b);
    }

    /* Fecha as conexões */
    outputStream.close();
    inputStream.close();
} catch (Exception e) {
    e.printStackTrace();
}
  • Thanks, later I’ll need to copy the bank to another folder

Browser other questions tagged

You are not signed in. Login or sign up in order to post.