[英]View SQLite database on device in Android Studio
I am using the latest version of Android Studio.我正在使用最新版本的 Android Studio。 When I run my app on the emulator, I am able to view my database by going through:当我在模拟器上运行我的应用程序时,我可以通过以下方式查看我的数据库:
tools -> Android Device Monitor -> clicking on the emulator in the left panel -> file explorer -> data -> data -> com.project-name
But this option isn't available when running my app on a device.但是在设备上运行我的应用程序时,此选项不可用。
I have checked related questions:我检查了相关问题:
and these questions are from 2011 and 2010. Are there any plugins I can use or other external tools?这些问题来自 2011 年和 2010 年。我可以使用任何插件或其他外部工具吗?
I haven't found any way to do that in Android Studio, but I access the db with a remote shell instead of pulling the file each time.我还没有在 Android Studio 中找到任何方法来做到这一点,但我使用远程 shell 访问数据库,而不是每次都提取文件。
Find all info here: http://developer.android.com/tools/help/adb.html#sqlite在此处查找所有信息: http : //developer.android.com/tools/help/adb.html#sqlite
1- Go to your platform-tools folder in a command prompt 1- 在命令提示符中转到您的平台工具文件夹
2- Enter the command adb devices
to get the list of your devices 2- 输入命令adb devices
以获取adb devices
列表
C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb devices
List of devices attached
emulator-xxxx device
3- Connect a shell to your device: 3- 将外壳连接到您的设备:
C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s emulator-xxxx shell
4- Navigate to the folder containing your db file: 4- 导航到包含您的 db 文件的文件夹:
cd data/data/<your-package-name>/databases/
5- run sqlite3 to connect to your db: 5- 运行 sqlite3 连接到您的数据库:
sqlite3 <your-db-name>.db
6- run sqlite3 commands that you like eg: 6- 运行您喜欢的 sqlite3 命令,例如:
Select * from table1 where ...;
Note: Find more commands to run below.注意:在下面找到更多要运行的命令。
There are a few steps to see the tables in an SQLite database:查看 SQLite 数据库中的表有几个步骤:
List the tables in your database:列出数据库中的表:
.tables
List how the table looks:列出表格的外观:
.schema tablename
Print the entire table:打印整个表:
SELECT * FROM tablename;
List all of the available SQLite prompt commands:列出所有可用的 SQLite 提示命令:
.help
The easiest way to see realtime Database are:查看实时数据库的最简单方法是:
You can use a very simple Android Studio's feature Database Inspector .您可以使用一个非常简单的 Android Studio 功能Database Inspector 。 Where you can inspect, query, and modify your app's databases using the new Database Inspector.您可以在其中使用新的数据库检查器检查、查询和修改应用程序的数据库。 For example, you can debug your running app by modifying values in your database and testing those changes on the device in real-time without leaving Android Studio .例如,您可以通过修改数据库中的值并在设备上实时测试这些更改来调试正在运行的应用程序,而无需离开 Android Studio 。
To get started, deploy your app to a device running API level 26 or higher and select View > Tool Windows > Database Inspector from the menu bar.首先,将您的应用程序部署到运行 API 级别 26 或更高级别的设备,然后从菜单栏中选择“查看”>“工具窗口”>“数据库检查器”。
Use the Android Debug Database library使用Android 调试数据库库
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
i.e. D/DebugDB: Open http://192.168.232.2:8080 in your browser
the link will be different and open it in the any browser链接会有所不同并在任何浏览器中打开它
That's it Enjoy!!!就是这样享受!!!
ADB forward tcp:8080 tcp:8080
如果您通过 USB 使用它,请运行ADB forward tcp:8080 tcp:8080
Below is the simplest solution for viewing sqlite database in Android.下面是在Android中查看sqlite数据库的最简单的解决方案。
https://github.com/facebook/stetho https://github.com/facebook/stetho
Steps to view SQLite DB查看 SQLite DB 的步骤
1) Add gradle dependency 1)添加gradle依赖
compile 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho:1.5.0' - for kotlin
2) In Application class 2)在应用类
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
3) Go to google chrome and type ' chrome://inspect/#devices
' to see connected devices and can access SQlite DB. 3) 转到谷歌浏览器并输入“ chrome://inspect/#devices
”以查看连接的设备并可以访问 SQlite DB。
This app is very useful, free and will remain free(Confirmed by the developer). 这个应用程序非常有用,免费并且将保持免费(由开发者确认)。 Very easy to add, edit and delete.非常容易添加、编辑和删除。
It will work for rooted device and emulator.它适用于有根设备和模拟器。 Also if you have DB file then you can browse it from SDCard of all devices including non-rooted.此外,如果您有 DB 文件,那么您可以从所有设备(包括非 root 用户)的 SDCard 中浏览它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.