0
다음 함수를 사용하여 웹 서버에서 일부 html을 다운로드하고 있습니다. 웹뷰에서 그걸 보여주고 싶습니다.Android HttpClient에서 진행 상황을 확인하는 방법은 무엇입니까?
private static final String request(String url) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
HttpGet get = new HttpGet(url);
try {
response = httpclient.execute(get);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
} catch (IOException e) {
//TODO Handle problems..
}
return responseString;
}
나는 AsynTask
에있는 함수를 사용하고 있습니다. 다음은 AsyncTask의 코드를 포함하는 함수입니다.
private void downloadInBackground(final String url, final WebView webview) {
new AsyncTask<String, String, String>() {
@Override
protected String doInBackground(String... strings) {
Log.d("asyncdebug", "sending!");
String response = request(url);
return response;
}
@Override
protected void onPostExecute(String response) {
Log.d("asyncdebug", "received!");
webview.loadDataWithBaseURL("http://www.somedomainname.com/new/",response, "text/html", "UTF-8", null);
super.onPostExecute(response);
}
@Override
protected void onProgressUpdate(String... param) {
Log.d("asyncdebug", "progressing... ");
}
}.execute("");
}
여기에서 다운로드 프로세스의 진행 상황을 어떻게 확인할 수 있습니까?
전체 예제 코드 .... http://stackoverflow.com/questions/11503791/progress-bar-completed-download-display-in-android – Dexter