View SQLite database on device in Android Studio
Connect to Sqlite3 via ADB Shell
I haven't found any way to do that in Android Studio, but I access the db with a remote shell instead of pulling the file each time.
Find all info here:
http://developer.android.com/tools/help/adb.html#sqlite
1- Go to your platform-tools folder in a command prompt
2- Enter the command adb devices
to get the list of your devices
C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb devices
List of devices attached
emulator-xxxx device
3- Connect a shell to your device:
C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s emulator-xxxx shell
4- Navigate to the folder containing your db file:
cd data/data/<your-package-name>/databases/
5- run sqlite3 to connect to your db:
sqlite3 <your-db-name>.db
6- run sqlite3 commands that you like eg:
Select * from table1 where ...;
Note: Find more commands to run below.
SQLite cheatsheet
There are a few steps to see the tables in an SQLite database:
List the tables in your database:
.tables
List how the table looks:
.schema tablename
Print the entire table:
SELECT * FROM tablename;
List all of the available SQLite prompt commands:
.help
Source : This SO answer..
On an Android Device where is located SQLite database, created by Room library
Whether you use Room, OrmLite or SQLite in Android all are located within databases folder of application package.
You can access the databases folder by following below steps.
- View > Tool Windows > Device File Explorer
From Device File Explorer go to data folder in which all the application packages are stored. Make sure that Emulator or device is connected.
- data > data
Then, find you application package and go to your database.
- com.company.my > databases > yourdatabasename.db
You can then save your database in your computer and do anything you want with it.
I use SQLiteBrowser to browse the database.
How to view sqlite database using real device
you can user Root Explore,before this,you must root your device and user root permission to run the app ,then open and find data folder and open the folder then continue find data folder and open ,you will find the app files in this device,find your packagename and you can find the db,you can use copy the db to sdcard
View contents of database file in Android Studio
Finally, i found a simplest solution which do not need to open the DDMS.
Actually, the solution is based on what @Distwo mentioned, but it don't have to be that complicated.
First, remember the path of your database file in the device, it should aways the same.
For example mine is:/data/data/com.XXX.module/databases/com.XXX.module.database
Second, execute this command which pulls your database file onto you PC
adb pull /data/data/com.XXX.module/databases/com.XXX.module.database /Users/somePathOnYourPC/
What you need to do is just copy and store this command, then you can use it again and again.
Third, if you got Permission Denied or something like that, just run adb root
before the previous command.
View sqlite database on android
Pull the sqlite database named as XYZ.db from your simulator or device using adb shell
command or GUI interface provided by the AndroidStudio. Then Open it using The Sqlite Browser. It's a killer app for sqlite browsing.
As android is shipped with the sqlite3, you could use command line to view the data base saved inside the device / emulator. Command reference is Listed Sqlite3 android command
If you feel lazy enough to discover how to pull files from emulator / device using adb pull
, following answer may help you.
how to pull
How to access my app's SQLite database in android device emulator for debugging
So i find this to be working:
adb root shell
adb shell
Then I'm able to navigate to my app's database folder and open it.
Related Topics
Check If Application Is Installed - Android
How to Change Font Face of Webview in Android
How to Use "Share Image Using" Sharing Intent to Share Images in Android
Android Camera Intent: How to Get Full Sized Photo
Push Notifications on Content Change
Animate the Transition Between Fragments
Percentage Width in a Relativelayout
Set Up Device For Development (? No Permissions)
How to Customize a Progress Bar in Android
How to Force Use of Overflow Menu on Devices With Menu Button
How to Sign Android App With System Signature
How to Return to a Parent Activity Correctly
How to Use Opencv in Using Gradle
How to Store(Bitmap Image) and Retrieve Image from SQLite Database in Android
Handling Registration Id Changes in Google Cloud Messaging on Android
Android Intent for Twitter Application
Android Multiple Email Attachments Using Intent
How to Add a Fragment to an Activity with a Programmatically Created Content View