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) ?
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.
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.
Database File Applications like Microsoft Access, Design Compiler Graphical, and LibreOffice use them routinely and can open the . db files they create.
Option 1:
Download and install SQLiteBrowser.
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:
Go to File Explorer (one of the tabs on the right), go to /data/data/databases
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:
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.
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.
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:
That's it. It goes without saying however that you should undo all these steps before publishing your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With