39

Is there a way for an Android user to browse the SQLite databases on his/her phone and view the data in the databases?

I use the SoftTrace beta program a lot. It's great but has no way that I can find to download the data it tracks to a PC.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
Justin C
  • 1,924
  • 4
  • 28
  • 43
  • The BEST solution was @Bob's answer at https://stackoverflow.com/questions/19194576/how-do-i-view-the-sqlite-database-on-an-android-device – Jeffrey Jul 01 '18 at 18:57

8 Answers8

26

The database for a specific app lives in /data/data/[packagename]/databases

The packagename is the package you define in your manifest, for instance /data/data/org.vimtips.supacount/databases/counts.db.

You can view it with adb shell and type sqlite3 /data/data/org.vimtips.supacount/databases/counts.db

Or you can pull it from the device to look at it with a third party utility, with a command like adb pull /data/data/org.vimtips.supacount/databases/counts.db ..

This assumes you have permission to view the database, which you might not have if you didn't write the app yourself... but in that case, is it actually a programming question?

synic
  • 26,359
  • 20
  • 111
  • 149
  • 23
    The techniques described here will work on an emulator and a rooted phone, but will not work on production phones. – CommonsWare Mar 27 '10 at 20:21
  • 1
    @CommonsWare Is there any way to look into the database of our application in a production phone? – Ads Nov 02 '12 at 07:26
  • It has been some time. My phone is not rooted and I can - while in developer mode - easily connect to it with adb. I am guessing this is a more recent development. – Yashima Feb 15 '13 at 12:48
  • 2
    @Ads I've been using `adb shell run-as my.ugly.package.name cat databases/data.db > data.db`, which will let you do a `pull` without root access. The databases I get out sometimes have weird rows, though. The weird rows do seem to be some artifact of the copy, as using `sqlite3` in the emulator gives normal rows. So who knows.. – Nolan Amy Mar 26 '13 at 05:26
  • ...just confirmed that `pull` gives valid data, so I'd recommend not using my command above if you can avoid it :) – Nolan Amy Mar 26 '13 at 05:41
  • I've managed to open the .../app_database directory using the ESFileExplorer app and a text editor. – Stevko Sep 09 '14 at 17:41
  • 2
    @Nolan `adb` mangles CRLF, so modify the command to strip them: `adb shell run-as my.ugly.package.name cat databases/data.db | sed 's/\r$//' > data.db` as per this thread: http://stackoverflow.com/a/14353315/105137 – kostmo Dec 27 '14 at 08:10
18

If you are using Eclipse, you can use a plugin called 'Questoid SQLite Browser' to browse the SQL Lite Database on your Android emulator:

  1. Install the plugin
  2. Restart eclipse
  3. Start your emulator
  4. Switch to DDMS
  5. Open database with plugin (as @synic mentioned previously, the DB is located here e.g. /data/data/my_project/databases)

Here is a more detailed tutorial: http://www.tylerfrankenstein.com/browse-android-emulator-sqlite-database-eclipse

tyler.frankenstein
  • 2,314
  • 1
  • 23
  • 36
8

Here is the free method that worked for me on a phone that is not rooted. Credit goes to this SO answer.

  1. Use adb backup -f backup.ab -noapk app.package.name
  2. On Windows download the Android Backup Extractor jar found on SourceForge here, then run java -jar abe.jar unpack backup.ab extractedbackup.tar. On Linux you can follow the dd instructions from the answer I gave credit to in the beginning.
  3. Download SQLite Database Browser from SourceForge here, then open the db file contained within extractedbackup.tar.

Personally, to make this process easier, I first added adb to my environment PATH. Then I made a backup folder where I store all of the files mentioned above. This keeps me from having to cd (change directory) all over the place.

Community
  • 1
  • 1
theblang
  • 10,215
  • 9
  • 69
  • 120
5

The Questoid plugin appears to cost $9 and requires registering. Another alternative on Windows is to download the open-source public-domain SQLLite Browser (link below) and then pull the database from the phone. In Eclipse you can do this from the File Browser, going to the /data/data/[packagename]/databases directory on the phone or emulator, and clicking "Pull a File From The Device" in the top right. Save the database locally, then open with the SQLite Browser.

http://sourceforge.net/projects/sqlitedbrowser/

joseph_morris
  • 705
  • 6
  • 13
  • Questoid's site seems to redirect to CellObject now. Their tools don't seem to cost anything (although you can donate) and they have a link to their code, hosted on Google Code. I just installed SQLite Browser and it works well for me without needing to first pull the database file to my workstation. – spaaarky21 Jan 10 '13 at 20:32
4

Actually the most available (yet still hacky) way of getting "live" results from a database while developing on emulator that I found is this:

  1. Create a script to pull the database from emulator, something like this

    #!/bin/bash
    
    ANDROID_HOME=/path/to/sdk
    ADB=$ANDROID_HOME/platform-tools/adb
    REMOTE_DB_PATH=/data/data/com.yourpackage.name/databases/your_db
    LOCAL_DB_PATH=.
    
    while true; do
    
      echo copying DB...
      `$ADB pull $REMOTE_DB_PATH $LOCAL_DB_PATH`
      sleep 3
    
    done
    

    Run it.

  2. Install SQLite Manager plugin for Firefox

  3. Open your local copy of the database (which is constantly overridden by the running script from step 1)

  4. Enter your SQL:

    enter image description here

  5. Select File->Reconnect

  6. Click Run SQL

The key trick is that reconnecting does not reset SQL entered on step 4 (as it does, for example, in SQLite Browser), so you can repeat steps 5,6 to see "live" results from your android database.

Note that this only works for emulator, it won't work for a real device (even a rooted one).

3

If you were lucky enough to get IntelliJ Ultimate then you can plug the device in, open 'Database' tab on the right, click +, select SQLite. The rest is trivial.

One thing to keep in mind with it is that you have to keep clicking "Synchronize" button on the database (or on selected table) to see the changes made externally, which is very annoying.

3

You can view you database from your app using this library . https://github.com/sanathp/DatabaseManager_For_Android

With this library you can manage your app SQLite database from you app itself. you can view the tables in your app database , update ,delete, insert rows to your tables

Its a single java activity file ,just add the java file to your source folder.When the development is done remove the java file from your src folder thats it .

It helped me a lot .Hope it helps you too .

You can view the 1 minute demo here : http://youtu.be/P5vpaGoBlBY

sanath_p
  • 2,198
  • 2
  • 26
  • 22
1

See this answer. You can use Stetho library from Facebook and then just browser you database from Chrome :)

Community
  • 1
  • 1
Yair Kukielka
  • 10,686
  • 1
  • 38
  • 46