我試圖獲取JSON數組我從互聯網上下載一個水平progressbardialog。 這裏是我當前的代碼HTTPGET JSONArray Android的進度
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方法。
服務器可能不會給內容長度,在這種情況下,你註定要使用不確定的風格。 – rds