Stetho是Facebook出品的一個強大的Android調試工具,使用該工具你可以在線查看數據庫、佈局、網絡請求等一切都是可視化佈局。你只需要在配置好代碼之後在谷歌瀏覽器中輸入 chrome://inspect 就可以(上圖)
這很像web開發中的審查元素選項
配置Stetho
添加額外包 gradle引用
compile 'com.facebook.stetho:stetho:1.1.0'
只有stetho庫是必須的,想查看網絡請求的話,需要使用下面的兩個庫之一(看你的網絡庫用的是okhttp還是urlconnection)
compile 'com.facebook.stetho:stetho-okhttp:1.1.0'
或者
compile 'com.facebook.stetho:stetho-urlconnection:1.1.0'
修改代碼
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}
}
開啓網絡請求查看若果你使用了okhttp庫,參考下面的代碼:
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());