Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) ?

like image 581
Scott Zhu Avatar asked Jul 08 '13 14:07

Scott Zhu


People also ask

How do I view Android database files?

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.

How do I view the contents of a SQLite file?

Click the File menu near the top right corner of the SQLite Database Browser window that opens and select Open Database. Browse to the location of the SQLite file you wish to read and click the file. Click the "Open" button. The SQLite file contents will display.

How do I view a .db file?

Database File Applications like Microsoft Access, Design Compiler Graphical, and LibreOffice use them routinely and can open the . db files they create.


1 Answers

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.

like image 117
Ojonugwa Jude Ochalifu Avatar answered Oct 09 '22 01:10

Ojonugwa Jude Ochalifu