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

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

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

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


当前回答

打开Android Studio底部的设备文件探索终端。

打开名为Data的文件夹,然后在Data内部再次打开Data文件夹。

向下滚动文件夹列表,找到带有你的.package.name的文件夹。打开文件夹your.package.name >数据库。你得到你的。databasename。右击你的。databaseName和Save as到C:/your/Computer/Directory。

进入C:/your/Computer/Directory,打开你的。databaseName with DB SQLite

其他回答

在Android Studio 3及以上,你可以在Android Studio右下角看到一个“设备文件资源管理器”部分。

打开它,然后你可以看到文件树,你可以在这个路径下找到一个应用程序数据库:

/data/data/{package_name}/databases/

右键单击db文件并另存为…(然后保存到桌面)。

然后使用SQLite sqlitebrowser.org(先下载并安装),单击“打开数据库”,选择保存的*.db文件,然后选择“浏览数据”选项卡并选择表以查看其内容。

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

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

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

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

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

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

从Android Studio查看数据库:

选项1:

Download and install SQLiteBrowser. Copy the database from the device to your PC: Android Studio versions < 3.0: Open DDMS via Tools > Android > Android Device Monitor Click on your device on the left. You should see your application: Go to File Explorer (one of the tabs on the right), go to /data/data/databases Select the database by just clicking on it. Go to the top right corner of the Android Device Monitor window. Click on the 'pull a file from the device' button: A window will open asking you where you want to save your database file. Save it anywhere you want on your PC. Android Studio versions >= 3.0: Open Device File Explorer via View > Tool Windows > Device File Explorer Go to data > data > PACKAGE_NAME > database, where PACKAGE_NAME is the name of your package (it is com.Movie in the example above) Right click on the database and select Save As.... Save it anywhere you want on your PC. Now, open the SQLiteBrowser you installed. Click on 'open database', navigate to the location you saved the database file, and open. You can now view the contents of your database.


选项2:

转到这个Github存储库,并按照自述文件中的说明在您的设备上查看您的数据库。你得到的结果是这样的:

就是这样。当然,在发布应用之前,你应该撤销所有这些步骤。

我把这个过程的unix命令行自动化放在一起,并把代码放在这里:

https://github.com/elliptic1/Android-Sqlite3-Monitor

它是一个shell脚本,以包名和数据库名作为参数,从附加的Android设备下载数据库文件,并针对下载的文件运行自定义脚本。然后,使用像“watch”这样的unix工具,你可以打开一个终端窗口,定期更新数据库脚本输出的视图。

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

使用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