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

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

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

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


当前回答

最简单的方法是使用Android调试数据库库(GitHub上的7.7k星)。

优点:

快速实现 查看所有数据库和共享首选项 直接编辑、删除、创建数据库值 在给定的数据库上运行任何SQLite查询 在数据中搜索 下载数据库 添加自定义数据库文件 不需要根设备

使用方法:

添加debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'来构建。gradle(模块); 启动应用程序; 找到日志中的调试链接(在LogCat中)(即D/DebugDB:在浏览器中打开http://192.168.232.2:8080,链接会不一样)并在浏览器中打开; 享受强大的调试工具!

重要的是:

不幸的是,它不能与模拟器一起工作 如果您通过USB使用它,请运行adb forward tcp:8080 tcp:8080 你的Android手机和笔记本电脑应该连接到同一个网络(Wifi或局域网)

欲了解更多信息,请访问GitHub上的图书馆页面。

其他回答

Follow the above steps to open the database folder of your app in Android Device explorer and in there you can see six files, The first three is named as android and the last three is named as your database name. You only have to work with the last three files, save these three files at your preferred location. You can save these files by right-clicking to the file and click save as button (like I have my database named as room_database and so three files are named as room_database, room_database-shm, and room_database-wal. Rename the corresponding file as follows:-

1)从room_database到room_database.db 2) room_database-shm到room_database.db-shm 3) room_database-wal到room_database.db-wal

现在在任何SQLite浏览器中打开第一个文件,这三个文件都将被填充到浏览器中。

打开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查看数据库:

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

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

要知道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/下载浏览器

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

谢谢,

虽然这是一个很老的问题,但我认为它今天仍然有意义。在最新版本的android studio中,我找到了一种方法来查看它(我不确定以前的版本中是否可用)。]

下面是如何查看数据库中的数据:

步骤:

Go to View > Tool Windows > Device File Explorer Then the folder data > data and you will see applications lists. There scroll down a little bit and see the package [ your package for application ]. After finding your package, see databases folder and select file, right click it and save [ download ] As you can't see the data directly, there is a tool, DB Browser for SQLite, go website https://sqlitebrowser.org/ Open Db browser and click open database and choose the database table you downloaded and it will show you the data.

新编辑

现在(当你阅读这篇文章的时候),这甚至更容易了,因为Android工作室已经提供了数据库检查器(就在右下角附近)。

点击它,你会看到数据库。 但是,请确保API的最小级别是26,如果不通过构建更改它。gradle文件作为minSdkVersion 26