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

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

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

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


当前回答

在Android 4.1 Canary 5预览版中引入了新的数据库检查器,您现在可以直接从IDE - https://developer.android.com/studio/preview/features?linkId=86173020#database-inspector检查、查询、修改和调试正在运行的应用程序中的SQLite数据库

支持数据库实时查询以及- https://developer.android.com/studio/preview/features?linkId=86173020#query

其他回答

从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存储库,并按照自述文件中的说明在您的设备上查看您的数据库。你得到的结果是这样的:

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

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

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

简单和容易的方法来查看Android工作室中的数据库内容。

# Android Studio 4.1 Canary 6及更高版本

你可以使用非常简单的Android Studio的数据库检查器功能。 在这里,您可以使用新的数据库检查器检查,查询和修改应用程序的数据库。例如,你可以通过修改数据库中的值来调试正在运行的应用程序,并在不离开Android Studio的情况下在设备上实时测试这些更改。

首先,将应用程序部署到运行API级别26或更高的设备上,并从菜单栏中选择“查看>工具Windows >数据库检查器”。

# Android Studio 4.0及以下版本

首先,在Android Studio中安装数据库导航插件

第二,重启Android Studio

第三,将数据库保存到默认位置,如:(C:\Users\User . 名称\文档\AndroidStudio\DeviceExplorer\模拟器或设备\数据\数据\包名\数据库)

第四,连接数据库导航器中保存的dbname_db文件

给出第三步中使用的相同的DB文件路径

i.e . (C)

最后,只需测试DB连接和打开控制台,做任何你想做的事情。

如果你想要刷新数据库,请重复步骤2并保存或刷新。

编码快乐! !

随着Android Studio 4.1 Canary和Dev预览版的发布,你可以使用一个名为

数据库检查员

安装AS 4.1+,运行应用程序,打开数据库检查器,现在你可以在数据库检查器面板的左侧查看你的数据库文件,然后选择表格查看内容。

实时查询

你可以使用run SQL选项运行你的查询,或者如果你使用Room,然后打开数据库检查器并运行应用程序,你可以通过单击@Query注释左侧的运行按钮在你的界面中运行DAO查询。

我使用windows 7,我的设备是一个模拟的android设备API 23。我想对于任何真实的设备都是一样的,只要它是根设备,API不超过23

进入工具-> Android -> Android设备监视器。 进入文件资源管理器。在我的例子中,它在data/data//app_webview/databases/file_0/1中

我必须手动在名为"1"的文件末尾添加。db