原來查看數據庫內容,我們一般都是將數據庫文件從手機導出,再用專門的軟件打開查看,比較繁瑣。最近發現了一個比較方便的方法:使用工具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打開管理窗口
如上圖所示,現在可以查看數據庫的內容了。