那麼,我的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版本中。你應該很久以前取代它了。無論如何,爲什麼大驚小怪?這只是一種方法。重寫它應該很簡單。你到目前爲止嘗試了什麼?你爲什麼不能自己做? –