自应用发布以来,我一直在使用Android Studio开发应用。

直到最近,一切都很好,我必须调试和检查数据库文件。由于我不知道如何直接看到数据库,当我调试生成数据库文件时,我不得不将数据库文件从我的手机导出到PC上。

为此,我必须打开DDMS >文件资源管理器。一旦我打开DDMS,我必须重新连接USB,我失去了调试线程。在检查数据库文件之后,我必须关闭DDMS并重新连接USB以回到调试模式。

这太复杂了。有人有更好的方法来做到这一点在Android Studio(我知道它更容易在Eclipse) ?


当前回答

我得把数据库从手机移到电脑上。现在我使用这个制作精良的免费应用程序,它有很多功能。它工作在API 4.1+与根设备。 如果你找到不用根也能吃的方法,请告诉我。

https://play.google.com/store/apps/details?id=com.lastempirestudio.sqliteprime

其他回答

经过所有的解决方案,我将建议

使用Stethos 让我们看看它有多简单

在构建中添加以下依赖项。gradle文件

implement 'com.facebook.stetho:stetho:1.5.0'
implement 'com.facebook.stetho:stetho-js-rhino:1.4.2'

然后转到mainActivity onCreate方法 添加以下行

Stetho.initializeWithDefaults(this);

这需要你

import com.facebook.stetho.Stetho;

现在在运行应用程序从android工作室,打开Chrome和地址栏类型 chrome: / /检查/

在资源选项卡>web SQL 检查数据库和表 玩它在实时容易

更新:在最近的Chrome版本中,Stethos被打破了。如果遇到问题,请尝试使用Edge开发工具代替Edge://inspect/#devices -参见:https://stackoverflow.com/a/67674265/14232521

我想知道为什么这里没有提到这个解决方案!

...在Android Studio 4.1及更高版本中…

1.在运行API级别26或更高的模拟器或连接设备上运行应用程序。

2.在菜单栏中选择“View > Tool Windows > Database Inspector”。

3.从下拉菜单中选择正在运行的app进程。

4.当前运行的应用程序中的数据库显示在“数据库”窗格中。展开要检查的数据库的节点。

要知道sqlite数据库存储由你在android studio,你需要遵循简单的步骤:

1.Run your application
2.Go to Tools--->Android---->Device Monitor
3.Find your application name in left panel
4.Then click on File Explorer tab
5.Select data folder
6.Select data folder again and find your app or module name
7.Click on your  database name
8.On right-top window you have an option to pull file from device.
9.Click it and save it on your PC
10.Use FireFox Sqlite manager to attach it to your project.

欲了解更多信息,此链接将是有用的。 http://www.c-sharpcorner.com/UploadFile/e14021/know-where-database-is-stored-in-android-studio/

要查看您的db文件中的数据,您需要下载sqlite浏览器或在任何浏览器中添加相同的插件,因此您需要在浏览器中打开文件并查看您的数据。

从http://sqlitebrowser.org/下载浏览器

这里是屏幕截图显示浏览器包含注册数据库

谢谢,

它是其他答案加加号的组合

Install DB Browser for SQLite Get the exact location from Device File Explorer for MyBase.db something like "/data/data/com.whatever.myapp/databases/MyBase.db" Set the project window from Android to Project - so you can see the files (build.gradle, gradle.properties,...etc) In Project window right click and chose Open in Terminal In terminal you are now in the root director of your application from the hardisk so execute: adb pull /data/data/com.whatever.myapp/databases/MyBase.db Now on the Project window of you Android Studio you have a file "MyBase.db" Double click your db file from Project and you can now browse/edit your databases in DB Browser When you are ready just do Write Changes in DB Browser so databases are saved on hardisk In terminal with the command: adb push MyBase.db /data/data/com.whatever.myapp/databases/MyBase.db you just send from the Hardisk to device the edited database.

最后,我找到了一个最简单的解决方案,不需要打开DDMS。

实际上,解决方案是基于@Distwo提到的,但它不必那么复杂。

首先,记住数据库文件在设备中的路径,它应该始终相同。 例如我的是:/data/data/com.XXX.module/databases/com.XXX.module.database

其次,执行这个命令,将数据库文件拉到PC上

 adb pull /data/data/com.XXX.module/databases/com.XXX.module.database /Users/somePathOnYourPC/

您需要做的就是复制并存储这个命令,然后您就可以一次又一次地使用它。

第三,如果你得到了Permission Denied或类似的情况,只需在前面的命令之前运行adb root。