To show all databases in the current connection, you use the . databases command. The . databases command displays at least one database with the name: main .
Android stores the file in the /data/data/packagename/databases/ directory. You can use the adb command or the File Explorer view in Eclipse ( Window > Show View > Other... > Android > File Explorer ) to view, move, or delete it.
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.
Here are step-by-step instructions (mostly taken from a combination of the other answers). This works even on devices that are not rooted.
Connect your device and launch the application in debug mode.
You may want to use adb -d shell "run-as com.yourpackge.name ls /data/data/com.yourpackge.name/databases/"
to see what the database filename is.
Notice: com.yourpackge.name
is your application package name. You can get it from the manifest file.
Copy the database file from your application folder to your SD card.
adb -d shell "run-as com.yourpackge.name cat /data/data/com.yourpackge.name/databases/filename.sqlite > /sdcard/filename.sqlite"
Notice: filename.sqlite is your database name you used when you created the database
Pull the database files to your machine:
adb pull /sdcard/filename.sqlite
This will copy the database from the SD card to the place where your ADB exist.
Install Firefox SQLite Manager: https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
Open Firefox SQLite Manager (Tools->SQLite Manager) and open your database file from step 3 above.
Enjoy!
UPDATE 2020
Database Inspector (for Android Studio version 4.1). Read the Medium article
For older versions of Android Studio I recommend these 3 options:
In build.gradle:
dependencies {
// Stetho core
compile 'com.facebook.stetho:stetho:1.5.1'
//If you want to add a network helper
compile 'com.facebook.stetho:stetho-okhttp:1.5.1'
}
Initialize the library in the application object:
Stetho.initializeWithDefaults(this);
And you can view you database in Chrome from chrome://inspect
The best way I found so far is using the Android-Debug-Database tool.
Its incredibly simple to use and setup, just add the dependence and connect to the device database's interface via web. No need to root the phone or adding activities or whatsoever. Here are the steps:
STEP 1
Add the following dependency to your app's Gradle file and run the application.
debugCompile 'com.amitshekhar.android:debug-db:1.0.0'
STEP 2
Open your browser and visit your phone's IP address on port 8080. The URL should be like: http://YOUR_PHONE_IP_ADDRESS:8080
. You will be presented with the following:
NOTE: You can also always get the debug address URL from your code by calling the method DebugDB.getAddressLog();
To get my phone's IP I currently use Ping Tools, but there are a lot of alternatives.
STEP 3
That's it!
More details in the official documentation: https://github.com/amitshekhariitbhu/Android-Debug-Database
The best way to view and manage your Android app database is to use the library DatabaseManager_For_Android.
It's a single Java activity file; just add it to your source folder. You can view the tables in your app database, update, delete, insert rows to you table. Everything from inside your app.
When the development is done remove the Java file from your src folder. That's it.
You can view the 5 minute demo, Database Manager for Android SQLite Database .
You can do this:
adb shell
cd /go/to/databases
sqlite3 database.db
sqlite>
prompt, type .tables
. This will give you all the tables in the database.db file.select * from table1;
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