利用Stetho在Chrome进行Android网络和数据库的调试

1.在build.gradle中添加

dependencies {    
      compile 'com.facebook.stetho:stetho:1.3.1'
}

2.在Application子类中 添加初始化的代码到Application内,完成这一步就具备查看数据库,查看View层级结构,使用默认dumpapp工具的能力了

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());    
      }
}

3.在AndroidManifest.xml中添加 android:name=”.MyApplication”

<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>

4.以上实现了查看数据库和SharedPreferences

运行程序后就会发现,在chrome中的网址栏输入:**chrome://inspect/即可看到你想看到的

5.如果需要查看网络请求首先

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

6.剩余就是网络请求代码

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值