2014-10-13 3 views
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(""); 
} 

여기에서 다운로드 프로세스의 진행 상황을 어떻게 확인할 수 있습니까?

+0

전체 예제 코드 .... http://stackoverflow.com/questions/11503791/progress-bar-completed-download-display-in-android – Dexter

답변

0

다운로드중인 데이터의 크기를 모르는 경우 불확실한 진행률 표시 줄을 사용할 수 있습니다. 당신의 onPostExecute에서 다음

 mProgressDialog = ProgressDialog.show(MyActivity.this, "", "Downloading...", true); 
     mProgressDialog.setCancelable(false); 

을 그리고 :

예를 들어, AsyncTask를 onPreExecute에이를 넣을 수 있습니다 여기에

 mProgressDialog.dismiss(); 

더 많은 정보 : Android ProgressDialog합니다.

관련 문제