1

I have connected my device at system. but i am not able to view my database in file-explore of DDMS. is there any easy way so i can get database file from android-device?

1
  • 1
    In real device is not Possible to see your DB. but you can export your DB in your SDCard and then open in SQLite Browser. Commented Jun 17, 2014 at 8:36

4 Answers 4

2

You have to follow below step to achieve your task :-

  1. Connect your device and launch the application in debug mode.

  2. Copy the database file from your application folder to your sd card: execute:

    ./adb -d shell "run-as com.yourpackge.name cat /data/data/com.yourpackge.name/databases/filename.sqlite > /sdcard/filename.sqlite"

  3. Pull the database files to your machine: execute:

    ./adb pull /sdcard/ execute: ./adb

  4. Install Firefox SQLLite Manager: https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

  5. Open Firefox SQLLite Manager and open your database file from step 3 above.

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

1 Comment

How to copy database since data is empty? See here
1
private void importDB() {
        try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();
                if (sd.canWrite()) {
                String currentDBPath = "//data//" + "<package name>"
                        + "//databases//" + "<database name>";
                String backupDBPath = "<backup db filename>"; // From SD directory.
                File backupDB = new File(data, currentDBPath);
                File currentDB = new File(sd, backupDBPath);

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

        }
    } catch (Exception e) {

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

    }
}

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

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + "<package name>"
                    + "//databases//" + "<db name>";
            String backupDBPath = "<destination>";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            Toast.makeText(getApplicationContext(), "Backup Successful!",
                    Toast.LENGTH_SHORT).show();

        }
    } catch (Exception e) {

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

    }
}

Here is the reference

Comments

0

Go to Android Studio->View->Tool Windows->Device File Explorer->data->data->select your package->databases->you can view your database

Comments

0

You can use stetho by facebook to debug any android native app.You can achieve that by including stetho in your dependencies.Then initialile stetho in your main application class within the overiden oncreate method once that is done ensure manifest is configured to your application class.You can check https://code.tutsplus.com/tutorials/debugging-android-apps-with-facebooks-stetho--cms-24205

    dependencies {
        compile 'com.facebook.stetho:stetho:1.5.0'
        compile 'com.facebook.stetho:stetho-okhttp:1.5.0'
        } 

then you can use Stetho.initializeWithDefaults(this); to initialize stetho go to chrome://inspect while the app is running then under websql you will be able to see all the tables in your database and write queries to manipulate the database

Comments

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.