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

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

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

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


当前回答

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

使用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版开始就绑定了一个数据库检查器。

但它有一个局限性:

数据库检查器仅适用于API级别26及更高的Android操作系统中包含的SQLite库。它不能与你的应用程序捆绑的其他SQLite库一起使用。

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

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

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

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

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

使用android sqlite作为服务器端数据库

遵循以下步骤:

找到数据库工具窗口,然后像下图一样点击它

点击加号图标,并选择Android SQLite如下图

将你的android设备连接到你的电脑 选择您关心的包,并选择如下图所示的数据库 在执行上述所有步骤之前,您必须确保拥有访问文件/data/data/ database/ databasfile .db的权限

在所有这些步骤之后,您将看到如下所示的数据库内容:

最后一点是

每次更新数据库数据时,都必须单击更新图标。

希望这对你有用!谢谢你!

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

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.