How to check SQLite DB table in Android Studio

This article will introduce how to check SQLite DB table in Android Studio in 2 ways.

1. Using "File Explorer" in Android Studio

Select [View] -> [Tool Windows] -> [Device File Explorer] in Android Studio to launch the Device File Explorer.

In Device File Explorer, if you enter the directory /data/data/[package name]/databases/, you can find the db file created by your app. Click the Save As... button to save it to your PC as follows. Device File Explorer - SQLite database

The /data/data/[package name]/ path is where the data of the app is stored, and the db file is stored under the databases folder.

1.1 Looking into Database file

To open the saved database file, you must install the Database Browser tool first.

You can download the SQLite Browser tool for each OS from sqlitebrowser.org. (If you are using a database other than SQLite, you can install a browser that can open the file.)

For Linux users, you can install and run sqlitebrowser with the following command.

$ sudo apt install sqlitebrowser
$ sqlitebrowser

If you run SQLite Browser and open the db file saved above, you can see which items are saved as follows. SQLITE Browser

2. Using "Android Debug Database" library

This library is for debugging Database and SharedPreferences. No need to root, just make sure your device and PC are connected to the same network.

When you run the app, the library creates a webpage so you can easily debug the database on your PC.

You can find more information about the library at GitHub - Android Debug Database.

2.1 How to use

Add the following dependencies to build.gradle.

dependencies {
    ...
    debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
}

And put it in Applicaiton or Activity so that the following code is executed.

This code prints the address of the webpage. So, you only need to put it where the code can be executed.

DebugDB.getAddressLog()

Now, if you run the app, DebugDB.getAddressLog() outputs the following log. You can copy the address of the log and run it on the web page.

08-30 16:53:08.947 10204 10204 D DebugDB : Open http://192.168.0.11:8080 in your browser

If you access http://192.168.0.11:8080 in your browser, you will see the following page.

You can check what items are in the DB table here. Android Debug Database webpage

Related Posts

codechachaCopyright ©2019 codechacha