作者:小树苗 | 来源:互联网 | 2023-10-11 18:37
原来查看数据库内容,我们一般都是将数据库文件从手机导出,再用专门的软件打开查看,比较繁琐。最近发现了一个比较方便的方法:使用工具stetho。使用方式在gradle中配置depen
原来查看数据库内容,我们一般都是将数据库文件从手机导出,再用专门的软件打开查看,比较繁琐。最近发现了一个比较方便的方法:使用工具stetho。
使用方式
在gradle中配置dependencies:
dependencies {
// Stetho core
compile 'com.facebook.stetho:stetho:1.3.1'
//If you want to add a network helper
compile 'com.facebook.stetho:stetho-okhttp3:1.3.1'
}
自定义一个MyApplication继承Application,在onCreate中初始化stetho:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
init();
}
private void init(){
Stetho.initializeWithDefaults(this);
new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
}
}
接着运行app到手机上。
然后打开chrome,输入网址chrome://inspect

检测到手机上的APP,点击inspect打开管理窗口

如上图所示,现在可以查看数据库的内容了。