我使用這個方法,我在裏面的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-or-not) – hungr