【发布时间】:2014-07-30 11:17:30
【问题描述】:
我正在使用我在 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;
}
连接丢失时我可以控制,但是当连接速度慢导致图像无法完全下载时,我没有任何控制。
如何查看图片是否未完全下载?
【问题讨论】:
-
使用异步任务下载图片。它会对你有很大帮助。
-
是的,该方法在异步任务中调用。我更新了问题:)
-
@hungr 不,它不是重复的。我的问题是,我认为它是由于连接速度慢而断开连接。这导致未完成的图像。但它不会丢弃任何错误。