Skip to content
Related Articles

Related Articles

Different Ways to View Contents of Database File in Android Studio
  • Difficulty Level : Medium
  • Last Updated : 06 Apr, 2021

Data is a group of information and it can be any kind of information – text, numbers, image, video. An organized collection of this data is called a Database. It is made so that the data can be accessed and managed easily. Data can be organized into tables, rows, columns as that make it easier to handle the data. The main purpose of having a database is to make it possible to work with huge amounts of data and be able to handle it. Databases store all the data that is required or was used in history by the website or app. There are a number of databases available, such as MySQL, Sybase, Oracle, MongoDB, Informix, PostgreSQL, SQL Server. A database management system (DBMS) is used to manage modern databases. Structured query language (SQL) is used to perform operations on the data stored in the database. There are many ways to view the content of databases in Android Studio. In this article, we are going to discuss five different methods to View the Contents of the Database File in Android Studio. 

  • Method 1: Without Opening DDMS
  • Method 2: Using Stetho library
  • Method 3: Using SQLiteBrowser
  • Method 4: Using ADB shell to connect to Sqlite3
  • Method 5: Using Database Inspector

Method 1: Without Opening DDMS

This method works on the Emulator only. 

In the first step, note down the path of the database file in your system. For example, let it be

/data/data/com.VVV.file/databases/com.VVV.file.database

Secondly, the database file needs to be pulled into the PC. Use the following command

adb pull /data/data/com.YYY.module/databases/com.YYY.module.database /Users/PATH/

If it shows permission denied or something similar to it, run adb root and run the previous command again.  



Method 2: Using Stetho library

In the first step – add stello dependency in build.gradle

compile 'com.facebook.stetho:stetho:1.5.0’

The second step – put the following command on the OnCreate() method of the main activity

Stetho.initializeWithDefaults(this);

The third step – Connect a device and run the app. Visit the following site using Chrome browser

chrome://inspect/#devices

Method 3: Using SQLiteBrowser

Download and install SQLiteBrowser. Copy the database from the device to the PC

  • For Android studio versions < 3.0
    • Open DDMS via Tools > Android > Android Device Monitor
    • The device should appear on the left, click on it.
    • All the applications running on the device will appear.
    • A tab on the bottom right corner appears named File explorer
    • In the file explorer, go to /data/data/databases
    • Select the database you want to see.
    • Click on the ‘pull a file from the device’ button. It is present in the top right corner of the Android device monitor window.
    • A pop-up window will ask to save the files. Save them wherever you want to.
  • For Android studio >= 3.0
    • Use View > Tool Windows > Device File Explorer to Open device file explorer. 
    • Go to data/data/PACKAGE_NAME/database. PACKAGE_NAME is the name of the package one is developing.
    • Right-click on the database and save it wherever you want using the Save As.  

Open the SQLiteBrowser and click on ‘open database’. Navigate to the place where the database was saved and open the database. The content of the database is displayed now.

Method 4: Using ADB shell to connect to Sqlite3

Go to the tools folder in the command prompt. Use the command adb devices to see the list of all devices

C:\ProgramFiles(x86)\Android\adt-bundle-windows\sdk\platform-tools>adb devices  
List of devices attached  
Redmi Note 7 pro device

Connect a shell to the device

C:\ProgramFiles(x86)\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s Redmi Note 7 pro shell

Go to the file containing the DB file

cd data/data/<package-name>/databases/

Execute sqlite3 to connect to DB

sqlite3 <db-name>.db

Run SQL commands to see any table. For example:

Select * from table1;

Method 5: Using Database Inspector

In the latest version of Android studios 4.1, the long-awaited tool Database Inspector made its appearance. It helps to inspect, query, and modify the database in the running app. Database inspector makes database editing as simple as editing a spreadsheet. Using room and observing the query result the changes are reflected in real-time in the app.

  • To open the database inspector select View -> Tool Windows -> Database Inspector from the menu bar of Android Studio.
  • Connect a device running on API level 26 or higher.
  • Run the app.
  • The database schemas appear and you can select the database you want to see.
  • The selected database is displayed.
Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!
My Personal Notes arrow_drop_up
Recommended Articles
Page :