View contents of database file in Android Studio

I have been using Android Studio to develop my app since it’s was released.

Everything works nice until recently, I have to debug together with checking the database file. Since I don’t know how to see the database directly, When I debugged to generate the database file, I have to export the database file from my phone to the PC.

In order to do this, I have to open DDMS > File Explorer. Once I open the DDMS, I have to reconnect the USB, and I lose my debug thread. After checking the database file, I have to close the DDMS and reconnect the USB again to get back to the debug mode.

It’s just too complicated. Does anyone have a better way to do this in Android Studio (I know it’s easier in Eclipse) ?

31 Answers
31

Viewing databases from Android Studio:

Option 1:

  1. Download and install SQLiteBrowser.

  2. Copy the database from the device to your PC:

    • Android Studio versions < 3.0:

      • Open DDMS via Tools > Android > Android Device Monitor

      • Click on your device on the left.
        You should see your application:
        enter image description here

      • Go to File Explorer (one of the tabs on the right), go to /data/data/databases
        enter image description here

      • Select the database by just clicking on it.

      • Go to the top right corner of the Android Device Monitor window. Click on the ‘pull a file from the device‘ button:
        enter image description here

      • A window will open asking you where you want to save your database file. Save it anywhere you want on your PC.

    • Android Studio versions >= 3.0:

      • Open Device File Explorer via View > Tool Windows > Device File Explorer

      • Go to data > data > PACKAGE_NAME > database, where PACKAGE_NAME is the name of your package (it is com.Movie in the example above)

      • Right click on the database and select Save As.... Save it anywhere you want on your PC.

  3. Now, open the SQLiteBrowser you installed. Click on ‘open database‘, navigate to the location you saved the database file, and open. You can now view the contents of your database.


Option 2:

Go to this Github repository and follow the instructions in the readme to be able to view your database on your device. What you get is something like this:

enter image description here

That’s it. It goes without saying however that you should undo all these steps before publishing your app.

Leave a Comment