使用Chrome来调试你的Android App
Github
使用Chrome来调试你的Android App
Facebook Stetho 使用学习
Android调试工具 stetho
####
添加依赖
1 2 3 4 5 6
| compile 'com.facebook.stetho:stetho:1.2.0'
compile 'com.facebook.stetho:stetho-urlconnection:1.2.0'
compile 'com.facebook.stetho:stetho-okhttp:1.2.0'
|
在Application中启动配置
1 2 3 4
| Stetho.initialize(Stetho.newInitializerBuilder(this) .enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this)) .build());
|
使用HttpUrlConnection调试网络请求,导入官方的一个网络请求类 Networker [stetho/stetho-sample/src/main/java/com/facebook/stetho/sample/Networker.java]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| public String sendHUCTPost(Context context, String url, Map<String, String> params) { PrintWriter out = null; BufferedReader in = null; String response = ""; try { URL realUrl = new URL(url);
StringBuffer requestParams = new StringBuffer(); if (params != null && params.size() > 0) {
Iterator<String> paramIterator = params.keySet().iterator(); while (paramIterator.hasNext()) { String key = paramIterator.next(); String value = params.get(key); requestParams.append(URLEncoder.encode(key, "UTF-8")); if (value != null) requestParams.append("=").append(URLEncoder.encode(value, "UTF-8")); requestParams.append("&"); }
} byte[] postBytes = String.valueOf(requestParams).getBytes(); Networker.HttpRequest request = Networker.HttpRequest.newBuilder() .friendlyName("ShangYun") .method(Networker.HttpMethod.POST) .url(url) .body(postBytes) .build(); Networker.get().submit(request, mStoreRssResponse);
} catch (Exception e) { e.printStackTrace(); } return response; }
public void sendOneReq() { Networker.HttpRequest request = Networker.HttpRequest.newBuilder() .friendlyName("Bai Du") .method(Networker.HttpMethod.GET) .url("http://www.baidu.com") .build(); Networker.get().submit(request, mStoreRssResponse); }
private final Networker.Callback mStoreRssResponse = new Networker.Callback() { @Override public void onResponse(Networker.HttpResponse result) { if (result.statusCode == 200) { String page22222=new String(result.body); System.out.println("page22222 : "+page22222); }else{ System.out.println("result.statusCode is not 200"); } } @Override public void onFailure(IOException e) { System.out.println("onFailure"); } };
|
最后在Chrome 浏览器输入 chrome://inspect/#devices 调试
参考列表
HTTP post body lost spuriously (HttpURLConnection & Jetty)
Post byte array in parameter
Convert a StringBuffer to a byte Array in Java