0

I create a application that use SQLite database and insert some data and then I need this full sqlite database file and i try to acces it but I didnot found database file, How to acces this file for use my PC?

1 Answer 1

2

If you are using Emulator then you can access your database, just by pulling it out from File Manager from following path: data/data/com.my.package/databases/mydb.sqlite

If you are running your application on your device then use following code to get database from your above filePath (since you cannot access internal file system of android device)

try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();

            if (sd.canWrite()) {
                String currentDBPath = "/data/com.yourApp.common/databases/yourApp.db";
                String backupDBPath = "/yourApp.db";
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd, backupDBPath);

                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB)
                            .getChannel();
                    FileChannel dst = new FileOutputStream(backupDB)
                            .getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                }
            }
        } catch (Exception e) {
        }

After that, once you have your db file, you can view it from Mozilla add On (Plugin) called SQLte Manager. Use this: https://addons.mozilla.org/en-us/firefox/addon/sqlite-manager/ to download it.

Sign up to request clarification or add additional context in comments.

3 Comments

you don't need to root your device, just write above code somewhere in your app, and view your database.
how to this line "sd.canWrite()" is true?
It will only work if you have provided permission in manifest file as "EXTERNAL_STORAGE" as you are going to store your db file on SD card.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.