Last Updated: February 25, 2016
·
570
· rodrigoayala

Query the internal DB of an Android Application

When developing an Android app that uses SQLite as database, sometimes you need to see the stored data to debug something.

An easy way to see the database, is retrieving the file and open it with the SQLite CLI to query.

To accomplish that, you need to know the package of the app, the name of the db, and type the following command:

For rooted devices:

PACKAGE=[package name] DB=[database name] && eval adb shell 'su -c cp /data/data/$PACKAGE/databases/$DB /sdcard' && adb pull /sdcard/$DB /tmp && sqlite3 /tmp/$DB

For emulator device:

PACKAGE=[package name] DB=[database name] && eval adb shell 'cp /data/data/$PACKAGE/databases/$DB /sdcard' && adb pull /sdcard/$DB /tmp && sqlite3 /tmp/$DB

Example

If the package of your app is cl.rodrigoayala.myapp , and the db name is myapp.db, go to your terminal and type;

On a rooted device:

PACKAGE=cl.rodrigoayala.myapp DB=myapp.db && eval adb shell 'su -c cp /data/data/$PACKAGE/databases/$DB /sdcard' && adb pull /sdcard/$DB /tmp && sqlite3 /tmp/$DB

On a emulator:

PACKAGE=cl.rodrigoayala.myapp DB=myapp.db && eval adb shell 'cp /data/data/$PACKAGE/databases/$DB /sdcard' && adb pull /sdcard/$DB /tmp && sqlite3 /tmp/$DB

Very easy, isn't? :)