Feb 01, 2016 How to browse Android Studio Emulator SQLite Database 4. In the Android Device Monitor, from the top menu, please navigate to Window - Show View, and then navigate - other - Questiod SQLite.
![]() ![]()
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)? Viewing databases from Android Studio:Edit: To view your database on an Emulator follow these steps (for actual device, scroll to the bottom):. Download and install.Copy the database from the device to your PC:.Android Studio versions 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 PACKAGENAME database, where PACKAGENAME 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.To view your database on your mobile device:Go to 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. I'm actually very surprised that no one has given this solution:Take a look at.I've used Stetho on several occasions for different purposes (one of them being database inspection). On the actual, they also talk about features for network inspection and looking through the view hierarchy.It only requires a little setup: 1 gradle dependency addition (which you can comment out for production builds), a few lines of code to instantiate Stetho, and a Chrome browser (because it uses Chrome devtools for everything).Update:You can now use Stetho to view Realm files (if you're using Realm instead of an SQLite DB):Update #2:You can now use Stetho to view Couchbase documents:Update #3:Facebook is focusing efforts on adding all Stetho features into its new tool, Flipper. Flipper already has many of the features that Stetho has.So, now may be a good time to make the switch. Simplest method when not using an emulator $ adb shell$ run-as your.package.name$ chmod 777 databases$ chmod 777 databases/databasename$ exit$ cp /data/data/your.package.name/databases/databasename /sdcard$ run-as your.package.name # Optional$ chmod 660 databases/databasename # Optional$ chmod 660 databases # Optional$ exit # Optional$ exit$ adb pull /sdcard/databasenameCaveats:I haven't tested this in a while.
![]()
It may not work on API=25.If the cp command isn't working for you try one of the following instead: # Pick a writeable directory other than /sdcard$ cp /data/data/your.package.name/databases/databasename # Exit and pull from the terminal on your PC$ exit$ adb pull /data/data/your.package.name/databases/databasenameExplanation:The first block configures the permissions of your database to be readable. This leverages run-as which allows you to impersonate your package's user to make the change. $ adb shell$ run-as your.package.name$ chmod 777 databases$ chmod 777 databases/databasename$ exit # Closes the shell started with run-asNext we copy the database to a world readable/writeable directory. This allows the adb pull user access. $ cp /data/data/your.package.name/databases/databasename /sdcardThen, replace the existing read/write privileges. This is important for the security of your app, however the privileges will be replaced on the next install. $ run-as your.package.name$ chmod 660 databases/databasename$ chmod 660 databases$ exit # Exit the shell started with run-asFinally, copy the database to the local disk.
$ exit # Exits shell on the mobile device (from adb shell)$ adb pull /sdcard/databasename.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |