浏览 Android SQLite 数据库中的数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2530548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
browse data in Android SQLite Database
提问by Justin C
Is there a way for an Android user to browse the SQLite databases on his/her phone and view the data in the databases?
Android 用户有没有办法在他/她的手机上浏览 SQLite 数据库并查看数据库中的数据?
I use the SoftTrace beta program a lot. It's great but has no way that I can find to download the data it tracks to a PC.
我经常使用 SoftTrace 测试版程序。这很棒,但我无法找到将其跟踪的数据下载到 PC 的方法。
采纳答案by synic
The database for a specific app lives in /data/data/[packagename]/databases
特定应用程序的数据库位于 /data/data/[packagename]/databases
The packagename is the package you define in your manifest, for instance /data/data/org.vimtips.supacount/databases/counts.db
.
包名是您在清单中定义的包,例如/data/data/org.vimtips.supacount/databases/counts.db
.
You can view it with adb shell
and type sqlite3 /data/data/org.vimtips.supacount/databases/counts.db
您可以查看它adb shell
并输入sqlite3 /data/data/org.vimtips.supacount/databases/counts.db
Or you can pull it from the device to look at it with a third party utility, with a command like adb pull /data/data/org.vimtips.supacount/databases/counts.db .
.
或者,您可以将其从设备中拉出以使用第三方实用程序查看它,使用类似adb pull /data/data/org.vimtips.supacount/databases/counts.db .
.
This assumes you have permission to view the database, which you might not have if you didn't write the app yourself... but in that case, is it actually a programming question?
这假设您有权查看数据库,如果您没有自己编写应用程序,您可能没有权限……但在这种情况下,它实际上是一个编程问题吗?
回答by tyler.frankenstein
If you are using Eclipse, you can use a plugin called 'Questoid SQLite Browser' to browse the SQL Lite Database on your Android emulator:
如果您使用的是 Eclipse,您可以使用名为“Questoid SQLite Browser”的插件在您的 Android 模拟器上浏览 SQL Lite 数据库:
- Install the plugin
- Restart eclipse
- Start your emulator
- Switch to DDMS
- Open database with plugin (as @synic mentioned previously, the DB is located here e.g. /data/data/my_project/databases)
- 安装插件
- 重启日食
- 启动你的模拟器
- 切换到 DDMS
- 使用插件打开数据库(正如前面提到的@synic,数据库位于此处,例如/data/data/my_project/databases)
Here is a more detailed tutorial: http://www.tylerfrankenstein.com/browse-android-emulator-sqlite-database-eclipse
这是一个更详细的教程:http: //www.tylerfrankenstein.com/browse-android-emulator-sqlite-database-eclipse
回答by theblang
Here is the free
method that worked for me on a phone that is not rooted
. Credit goes to this SO answer.
这是在free
手机上对我有用的方法is not rooted
。归功于这个 SO answer。
- Use
adb backup -f backup.ab -noapk app.package.name
- On Windows download the
Android Backup Extractor
jar found on SourceForge here, then runjava -jar abe.jar unpack backup.ab extractedbackup.tar
. On Linux you can follow thedd
instructions from the answer I gave credit to in the beginning. - Download
SQLite Database Browser
from SourceForge here, then open thedb
file contained withinextractedbackup.tar
.
- 用
adb backup -f backup.ab -noapk app.package.name
- 在Windows上下载的
Android Backup Extractor
罐子在SourceForge上找到这里,然后运行java -jar abe.jar unpack backup.ab extractedbackup.tar
。在 Linux 上,您可以按照dd
我在开始时给予的答案中的说明进行操作。 - 在此处
SQLite Database Browser
从 SourceForge下载,然后打开包含在.db
extractedbackup.tar
Personally, to make this process easier, I first added adb to my environment PATH. Then I made a backup folder where I store all of the files mentioned above. This keeps me from having to cd (change directory) all over the place.
就个人而言,为了使这个过程更容易,我首先将 adb 添加到我的环境 PATH 中。然后我创建了一个备份文件夹,用于存储上面提到的所有文件。这使我不必到处 cd (更改目录)。
回答by joseph_morris
The Questoid plugin appears to cost $9 and requires registering. Another alternative on Windows is to download the open-source public-domain SQLLite Browser (link below) and then pull the database from the phone. In Eclipse you can do this from the File Browser, going to the /data/data/[packagename]/databases directory on the phone or emulator, and clicking "Pull a File From The Device" in the top right. Save the database locally, then open with the SQLite Browser.
Questoid 插件似乎要花费 9 美元并且需要注册。Windows 上的另一种选择是下载开源公共域 SQLLite 浏览器(下面的链接),然后从手机中提取数据库。在 Eclipse 中,您可以从文件浏览器执行此操作,转至手机或模拟器上的 /data/data/[packagename]/databases 目录,然后单击右上角的“从设备中提取文件”。将数据库保存在本地,然后使用 SQLite 浏览器打开。
回答by Denis Kniazhev
Actually the most available (yet still hacky) way of getting "live" results from a database while developing on emulatorthat I found is this:
实际上,在我发现的模拟器上开发时,从数据库中获取“实时”结果的最可用(但仍然很笨拙)的方法是:
Create a script to pull the database from emulator, something like this
#!/bin/bash ANDROID_HOME=/path/to/sdk ADB=$ANDROID_HOME/platform-tools/adb REMOTE_DB_PATH=/data/data/com.yourpackage.name/databases/your_db LOCAL_DB_PATH=. while true; do echo copying DB... `$ADB pull $REMOTE_DB_PATH $LOCAL_DB_PATH` sleep 3 done
Run it.
Open your local copy of the database (which is constantly overridden by the running script from step 1)
Enter your SQL:
Select
File->Reconnect
- Click
Run SQL
创建一个脚本来从模拟器中拉取数据库,像这样
#!/bin/bash ANDROID_HOME=/path/to/sdk ADB=$ANDROID_HOME/platform-tools/adb REMOTE_DB_PATH=/data/data/com.yourpackage.name/databases/your_db LOCAL_DB_PATH=. while true; do echo copying DB... `$ADB pull $REMOTE_DB_PATH $LOCAL_DB_PATH` sleep 3 done
运行。
打开数据库的本地副本(它会不断被步骤 1 中的运行脚本覆盖)
输入您的 SQL:
选择
File->Reconnect
- 点击
Run SQL
The key trick is that reconnecting does not reset SQL entered on step 4 (as it does, for example, in SQLite Browser), so you can repeat steps 5,6to see "live" results from your android database.
关键技巧是重新连接不会重置在步骤 4 中输入的 SQL(例如,在SQLite Browser 中),因此您可以重复步骤5,6以查看来自您的 android 数据库的“实时”结果。
Note that this only works for emulator, it won't work for a real device (even a rooted one).
请注意,这仅适用于模拟器,它不适用于真实设备(即使是有根设备)。
回答by Denis Kniazhev
If you were lucky enough to get IntelliJ Ultimate then you can plug the device in, open 'Database' tab on the right, click +, select SQLite. The rest is trivial.
如果您有幸获得 IntelliJ Ultimate,那么您可以插入设备,打开右侧的“数据库”选项卡,单击 +,选择 SQLite。其余的都是微不足道的。
One thing to keep in mind with it is that you have to keep clicking "Synchronize" button on the database (or on selected table) to see the changes made externally, which is very annoying.
要记住的一件事是,您必须不断单击数据库(或选定表)上的“同步”按钮才能查看外部所做的更改,这非常烦人。
回答by sanath_p
You can view you database from your app using this library . https://github.com/sanathp/DatabaseManager_For_Android
您可以使用此库从您的应用程序查看您的数据库。https://github.com/sanathp/DatabaseManager_For_Android
With this library you can manage your app SQLite database from you app itself. you can view the tables in your app database , update ,delete, insert rows to your tables
使用这个库,您可以从您的应用程序本身管理您的应用程序 SQLite 数据库。您可以查看应用程序数据库中的表,更新,删除,向表中插入行
Its a single java activity file ,just add the java file to your source folder.When the development is done remove the java file from your src folder thats it .
它是一个单独的 java 活动文件,只需将 java 文件添加到您的源文件夹中。开发完成后,从 src 文件夹中删除 java 文件就是这样。
It helped me a lot .Hope it helps you too .
它帮助了我很多。希望它也能帮助你。
You can view the 1 minute demo here : http://youtu.be/P5vpaGoBlBY
您可以在此处查看 1 分钟演示:http: //youtu.be/P5vpaGoBlBY