How do I view the SQLite database on an Android de

2019-01-01 07:58发布

This question already has an answer here:

I have a set of data in an SQLite database. I need to view the database on a device. How do I do that?

I have checked in ddms mode. The data in file explorer is empty.

20条回答
高级女魔头
2楼-- · 2019-01-01 08:37

I found very simple library stetho to browse sqlite db of app in chrome, see

查看更多
一个人的天荒地老
3楼-- · 2019-01-01 08:38

Here are step-by-step instructions (mostly taken from a combination of the other answers). This works even on devices that are not rooted.

  1. Connect your device and launch the application in debug mode.

  2. 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.

  1. 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

  1. 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.

  1. Install Firefox SQLite Manager: https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

  2. Open Firefox SQLite Manager (Tools->SQLite Manager) and open your database file from step 3 above.

  3. Enjoy!

查看更多
孤独总比滥情好
4楼-- · 2019-01-01 08:38

This works with Android 6.0 (debuggable apps at least):

adb shell "run-as your.package.name cp /data/data/your.package.name/databases/you-db-name  /sdcard/file_to_write"

Then you simply can view the DB with aSQLiteManager for instance.

查看更多
临风纵饮
5楼-- · 2019-01-01 08:38

There is TKlerx's Android SQLite browser for Eclipse, and it's fully functional alongside Android Studio. I'll recommend it, because it is immensely practical.

To install it on Device Monitor, just place the JAR file in [Path to Android SDK folder]/sdk/tools/lib/monitor-[...]/plugins.

查看更多
路过你的时光
6楼-- · 2019-01-01 08:39

You can try SQLiteOnWeb. It manages your SQLite database in the browser.

查看更多
若你有天会懂
7楼-- · 2019-01-01 08:40

Taken from here, you can try:

  1. Facebook's open source Stetho library

In build.gradle:

dependencies {
  // Stetho core
  compile 'com.facebook.stetho:stetho:1.5.0'        
  //If you want to add a network helper
  compile 'com.facebook.stetho:stetho-okhttp:1.5.0'
}

Initialize the library in the application object:

Stetho.initializeWithDefaults(this);

And you can view you database in Chrome from chrome://inspect

  1. Another option is this plugin (not free)
  2. And the last one is this free/open source library to see db contents in the browser https://github.com/amitshekhariitbhu/Android-Debug-Database
查看更多
登录 后发表回答