2014-07-10 3 views
0

나는 내가 AsyncTask를 내부에서 호출이 방법을 사용하여 비트 맵을 다운로드하고 중단 : 연결이 원인이 느린 경우는 이미지 다운로드

public static Bitmap downloadBitmap(String url) { 
    final AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); 
    final HttpGet getRequest = new HttpGet(url); 
    try { 
     HttpResponse response = client.execute(getRequest); 
     final int statusCode = response.getStatusLine().getStatusCode(); 
     if (statusCode != HttpStatus.SC_OK) { 
      return null; 
     } 
     final HttpEntity entity = response.getEntity(); 
     if (entity != null) { 
      InputStream inputStream = null; 
      try { 
       System.setProperty("http.keepAlive", "false"); 
       inputStream = entity.getContent(); 
       final Bitmap bitmap = BitmapFactory.decodeStream(inputStream); 
       return bitmap; 
      } finally { 
       if (inputStream != null) { 
        inputStream.close(); 
       } 
       entity.consumeContent(); 
      } 
     } 
    } catch (Exception e) { 
     getRequest.abort(); 
    } finally { 
     if (client != null) 
      client.close(); 
    } 
    return null; 
} 

내가 연결이 끊어 제어 할 수 있습니다, 그러나, 나는 어떤이 없습니다 이미지가 완전히 다운로드되지 않습니다.

이미지가 완전히 다운로드되지 않았는지 어떻게 확인할 수 있습니까?

+0

비동기 작업을 사용하여 이미지를 다운로드하십시오. 그것은 당신을 많이 도울 것입니다. –

+0

예, 메서드는 asynctask 내부에서 호출됩니다. 나는 질문을 업데이트했다 : –

+0

가능한 [이미지 다운로드 프로세스가 완료되었는지 여부를 확인하는 방법] (http://stackoverflow.com/questions/13965294/how-to-check-whether-the-process -of-download-image-is-completed 또는 not) – hungr

답변

0

내 솔루션을 사용하기 전에 널 (null)은 변수에 이미지 파일 이름을 넣어 스트림에서 파일 크기와 다운로드 한 파일을 확인할 수 있었다. 일치하지 않으면 파일을 삭제합니다.

0

이 하나를 시도해보십시오! Drawable.createFromPath (파일 경로를) =이

+0

나는 그것을 얻지 않는다. 어떻게 사용합니까? –