How to get the live view of inserted data in Sqlite database on Android Studio

If You Want to Show a data on Log try below code :

for (Contact cn : contacts) {
            String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Phone: " + cn.getPhoneNumber();
                // Writing Contacts to log
        Log.d("Name: ", log);

Other Way to show a database see below steps:

  1. Go to Tools -> DDMS or click the Device Monitor icon next to SDK Manager in Tool bar.
  2. Device Monitor window will open. In File Explorer tab, click data -> data -> your project name. After that your databases file will open. Click pull a file from device icon. Save the file using .db extension.
  3. Open FireFox, Press Alt , Tools -> SQLiteManager.
  4. Follow Database -> connect to Database -> browse your database file and click ok. Your SQLite file will opened now.

If you Download a database on DDMS then You download

DB.Browser.for.SQLite-3.10.1-win64

and put the database file on this software and you get the data.


NEW UPDATE OF DDMS

  • I'll Update My Answer becoz now a days Android Studio update in Android Studio 3.1 or up to other like now 3.2 in this Studio DDMS function is not available but Don't Worry i have another solution.

  • In your android Studio See right side Bottom Corner there is one Option like Device File Explorer Click on this button

After that you can see like below image is open on your screen :

enter image description here

Now select data -> data -> your project name. :)


I can't believe no one's mentioned this but what you are probably looking for is Android Debug Database

Works great with Android Room as well and you can view, edit tables and records.


Although you approved Cassius Clay's answer, if you need to process the raw data

root is not needed ( if it's not on the sdcard follow @Ankit 's answer )

import os
import sys
import subprocess
import sqlite3
import pandas as pd

arg_folder = sys.argv[1]  # root folder to recursively search db files from
output_lines = subprocess.check_output(['adb', 'shell', ('ls -R %s' % arg_folder)]).decode('utf-8').splitlines()
db_files = []
current_folder = ''
for line in output_lines:
    """
        Output example for 'ls -R /data/data':
            /data/data/org.fdroid.fdroid/files/fdroid/repo/icons:

            /data/data/org.fdroid.fdroid/shared_prefs:
            apks-pending-install.xml
            org.fdroid.fdroid_preferences.xml

            /data/data/ru.meefik.busybox:
            cache
            files
            lib
            shared_prefs

        if line contains '/' it's a directory, we want to extract the full path for '.db' files
    """
    if line.__contains__('/'):
        current_folder = line
    elif line.endswith('.db'):
        db_files.append('%s/%s' % (current_folder[:-1], line))
print("Listing databases..")

while True:
    try:
        for idx, full_path in enumerate(db_files):
            print("{}) {}".format(idx + 1, full_path))
        i = input("Enter database number : ")
        db = db_files[int(i) - 1]  # selected database
        subprocess.check_output(['adb', 'pull', db])  # pulling the .db file from device to local
        db = db.split('/')[-1]  # "/data/data/com.app/folder/private.db".split('/')[-1] = private
        conn = sqlite3.connect(db)
        # getting list of current database tables
        tables = conn.execute("SELECT name FROM sqlite_master WHERE type='table';").fetchall()
        for table in tables:
            table = table[0]  # little fix, it comes as a tuple
            print('%s%s' % (db[:-2], table))
            with pd.option_context('display.width', 1000):  # setting terminal width to view all table columns inline
                print(pd.read_sql_query("SELECT * FROM %s" % table, conn))  # print table content
            print('- ' * 50)  # table print separator
        # cleanup
        if input('remove database file (from local) [y/N] ? ').lower() == 'y':
            print('removing ', db)
            os.remove(db)
        # repeat
        c = input("Press ENTER to continue or CTRL+C to Quit..")
    except KeyboardInterrupt:
        exit(0)

preview 2..

Here is a less human-friendly very-long-one-liner

read -p "enter root folder to recursively search db files from: " f;dbs=( $(adb shell ls -R $f |
    while read line
    do
        line=$(echo $line | tr -d '\r')
        if [[ "$line" =~ ^/.*:$ ]]
        then
            dir=${line%:}
        elif [[ "$line" = "opendir failed" ]]
        then
            echo "$dir - permission denied"
        else
            if [[ "$dir" = "/" ]]; then dir=""; fi
            echo "$dir/$line" | grep '\.db$'
        fi
    done)
);echo ${dbs[@]}; dbs+=(exit);select db in "${dbs[@]}"; do
  [[ $db == exit ]] && break
  echo "You have chosen $db"
  adb pull $db
  python -c 'import sqlite3;import pandas as pd;db=sqlite3.connect("'${db##*/}'");tables=db.cursor().execute("SELECT name FROM sqlite_master WHERE type=\"table\";").fetchall();print([pd.read_sql_query("SELECT * FROM %s" % t[0], db) for t in tables]);'
done

GIF because I'm too lazy to document

preview..