我正在尝试为从 Internet 下载的 json 数组获取水平进度条对话框。这是我当前的代码
protected JSONArray doInBackground(Date... arg0) {
try {
BufferedReader in = null;
String result = null;
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setSoTimeout(client.getParams(), 30000);
HttpConnectionParams.setConnectionTimeout(client.getParams(),
30000);
String getter = arg0[0].getDate();
URI website = new URI("http://10.0.2.2/bmorg/getEvent?day=" + getter);
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response
.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.seperator");
while ((l = in.readLine()) != null) {
sb.append(l + nl);
}
in.close();
result = sb.toString();
return new JSONArray(result);
} catch (Exception e) {
_worked = false;
e.printStackTrace();
}
return null;
}
这工作正常,但我想要的是下载状态。我不知道如何从我的 Http 请求和下载的字节中获取大小以将其放入进度条的 onChange 方法。