利用Stetho在Chrome进行Android网络和数据库的调
1.在build.gradle中添加
<pre>
dependencies {
compile 'com.facebook.stetho:stetho:1.3.1'
}
</pre>
2.在Application子类中 添加初始化的代码到Application内,完成这一步就具备查看数据库,查看View层级结构,使用默认dumpapp工具的能力了
<pre>
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
//方法一
//Stetho.initializeWithDefaults(this);
//方法二
Stetho.initialize(Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}
}
</pre>
3.在AndroidManifest.xml中添加 android:name=".MyApplication"
<pre>
<application
android:name=".base.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".home.HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</pre>
4.以上实现了查看数据库和SharedPreferences
运行程序后就会发现,在chrome中的网址栏输入:**chrome://inspect/即可看到你想看到的
5.如果需要查看网络请求首先
<pre>
<uses-permission android:name="android.permission.INTERNET"/>
</pre>