나는 내가 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;
}
내가 연결이 끊어 제어 할 수 있습니다, 그러나, 나는 어떤이 없습니다 이미지가 완전히 다운로드되지 않습니다.
이미지가 완전히 다운로드되지 않았는지 어떻게 확인할 수 있습니까?
비동기 작업을 사용하여 이미지를 다운로드하십시오. 그것은 당신을 많이 도울 것입니다. –
예, 메서드는 asynctask 내부에서 호출됩니다. 나는 질문을 업데이트했다 : –
가능한 [이미지 다운로드 프로세스가 완료되었는지 여부를 확인하는 방법] (http://stackoverflow.com/questions/13965294/how-to-check-whether-the-process -of-download-image-is-completed 또는 not) – hungr