I am using following function to download some html from webserver. and then want to show that in webview.
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;
}
I am using the function in an AsynTask
. Here's the function which contains AsyncTask's code.
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("");
}
How can I get the update progress of the download process here?