利用Stetho在Chrome進(jìn)行Android網(wǎng)絡(luò)和數(shù)據(jù)庫的調(diào)試

1.在build.gradle中添加

<pre>
dependencies {
compile 'com.facebook.stetho:stetho:1.3.1'
}
</pre>

2.在Application子類中 添加初始化的代碼到Application內(nèi),完成這一步就具備查看數(shù)據(jù)庫,查看View層級結(jié)構(gòu),使用默認(rèn)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.以上實現(xiàn)了查看數(shù)據(jù)庫和SharedPreferences

運行程序后就會發(fā)現(xiàn),在chrome中的網(wǎng)址欄輸入:**chrome://inspect/即可看到你想看到的

5.如果需要查看網(wǎng)絡(luò)請求首先

<pre>
<uses-permission android:name="android.permission.INTERNET"/>
</pre>

6.剩余就是網(wǎng)絡(luò)請求代碼

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容