我正在使用这种方法下载位图,我在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;
}当连接丢失时,我可以控制,但是,当连接慢到导致映像无法完全下载时,我没有任何连接。
如何检查图像是否未被完全下载?
发布于 2014-07-30 03:17:30
我的解决方案是将图像文件名放入一个变量中,并从流和下载的文件中检查文件大小。如果不匹配,我将删除该文件。
发布于 2014-07-10 06:34:53
试一试: Drawable.createFromPath(filePath)!= null,然后再使用它
https://stackoverflow.com/questions/24669613
复制相似问题