View and modify data in SQLite tables in Android Studio

Programming

I am personally developing the following Omikuji application for smartphones using Flutter.

[iOS]
https://apps.apple.com/us/app/%E5%A4%A7%E5%BE%A1%E5%BF%83%E3%82%A2%E3%83%97%E3%83%AA/id1627544916

[Android]
https://play.google.com/store/apps/details?id=jp.sikisimanomiti.oomigokoro

The Omikuji application uses SQLite to hold some data from the API locally. Still, in developing and debugging the application, I wanted to view the data in the SQLite table via GUI, so I researched how to view it.

How to view SQLite data in Android Studio

① View using the Database Inspector in Android Studio.
② Use the ADB command.

① View using the Database Inspector in Android Studio

1 Run the application in the emulator.
2 Select [View] > [Tool Window] > [App Inspection] from the menu bar.

3 When “App Inspection” opens, select the running app process.

4 Select the “Database Inspector” tab.

5 The “Database” pane displays the database of the connected application. Click on the table you want to view the stored data. Double-click on a cell to edit and modify the data.

Reference

Debug your database with the Database Inspector

② Use the ADB command

Although DB Browser for SQLite cannot directly reference Android SQLite files, you can use the ADB command to copy Android SQLite files locally from the actual device or emulator. Instead, we want to copy the file locally and open it with DB Browser for SQLite.

The SQLite file is in the following directory in the terminal in /data/data/[package name]/files/, so I will copy it locally with the following command.

// Get permission to access the file & copy it to a browseable directory & copy it locally
$ adb shell 'run-as [package name] cat /data/data/[package name]/files/sample.db > /sdcard/sample.db' && adb pull /sdcard/sample.db ./sample.db

// Open a local copy of SQLite in DB Browser for SQLite
$ open -a "DB Browser for SQLite.app" sample.db

Finally

I think you can develop comfortably using Database Inspector because I could view and modify the data in the GUI.

コメント

タイトルとURLをコピーしました