MCPcopy Create free account
hub / github.com/MeigenChou/DCTimer-Android / getContent

Method getContent

app/src/main/java/com/dctimer/util/Utils.java:67–93  ·  view source on GitHub ↗
(String urlStr)

Source from the content-addressed store, hash-verified

65 }
66
67 public static String getContent(String urlStr) {
68 try {
69 URL url = new URL(urlStr);
70 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
71 conn.setConnectTimeout(20000); //设置连接超时时间
72 conn.setReadTimeout(30000);
73 //conn.setRequestMethod("POST"); //设置以Post方式提交数据
74 //conn.setDoOutput(true);
75 //conn.setDoInput(true);
76 //conn.setUseCaches(false);
77 conn.connect();
78 int res = conn.getResponseCode();
79 if (res == HttpURLConnection.HTTP_OK) {
80 InputStreamReader is = new InputStreamReader(conn.getInputStream(), "GB2312");
81 BufferedReader reader = new BufferedReader(is);
82 StringBuilder sb = new StringBuilder();
83 String line;
84 while ((line = reader.readLine()) != null) {
85 sb.append(line).append('\t');
86 }
87 reader.close();
88 return sb.toString();
89 } else return "error code: " + res;
90 } catch (Exception e) {
91 return "error open url:" + urlStr;
92 }
93 }
94
95 public static boolean isTablet(Context context) {
96 return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)

Callers 1

runMethod · 0.95

Calls 2

toStringMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected