那么,我的ImageDownloader类是与新的Sdk打破。我现在怎么去做这项工作?任何可能我只需要替换下面的一些类而不对我的代码做重大更改?在gradle这个文件AndroidHttpClient已弃用
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
或本:
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) {
Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url);
return null;
}
final HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
try {
inputStream = entity.getContent();
final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
return bitmap;
} finally {
if (inputStream != null) {
inputStream.close();
}
entity.consumeContent();
}
}
} catch (Exception e) {
// Could provide a more explicit error message for IOException or IllegalStateException
getRequest.abort();
Log.w("ImageDownloader", "Error while retrieving bitmap from " + url);
} finally {
if (client != null) {
client.close();
}
}
return null;
}
到底什么是坏,什么错误,你现在接受? – Sam
你为什么曾经使用过'AndroidHttpClient'?这是字面上古老的,它已被推荐多年。仅在最早的Android版本中。你应该很久以前取代它了。无论如何,为什么大惊小怪?这只是一种方法。重写它应该很简单。你到目前为止尝试了什么?你为什么不能自己做? –