首页 技术 正文
技术 2022年11月14日
0 收藏 827 点赞 3,930 浏览 1530 个字

Android 借助Stetho在Chrome上调试Android网络、数据库、Sharedpreferences

转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/61919840

本文出自【赵彦军的博客】

简介

StethoFacebook开源的Andorid调试工具。当你的应用集成Stetho时,开发者可以访问Chrome,在Chrome Developer Tools中查看应用布局,网络请求,sqlitepreference等等,可视化一切应用操作(更重要的是不用root)。

官网: http://facebook.github.io/stetho/

如何集成

  • build.gradle添加
dependencies {
compile 'com.facebook.stetho:stetho-okhttp3:1.4.2'
}
  • 初始化
package com.zyj.stetho;
import android.app.Application;
import com.facebook.stetho.Stetho;/**
* Created by ${zhaoyanjun} on 2017/3/13.
*/public class MyApplication extends Application { @Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
  • 用数据线把手机和电脑连起来,运行App , 打开Chrome输入chrome://inspect/#devices 。可以看到下面的界面。

chrome调试Android 数据库、SharedPreferences

点击inspect将会看到如下Developer Tools界面,如果这个界面出不来,看看是否需要翻墙,你懂得:

点击数据库的表,可以看到数据库里面的数据内容:

点击SharedPreferences可以看到:

查看网络请求

  • 首选基于OkHttp3.x添加拦截器
void net(){
String url = "https://www.baidu.com/" ; OkHttpClient client = new OkHttpClient.Builder()
.addNetworkInterceptor( new StethoInterceptor()) //添加拦截器
.build() ; Request request = new Request.Builder()
.url(url)
.build(); Response response = null;
try {
response = client.newCall(request).execute();
if ( response.isSuccessful() ) {
String result = response.body().string() ;
Log.e( "zhao", "net: " + result );
}
} catch (IOException e) {
e.printStackTrace();
}
}

总结:

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,816
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,899