Here is the code that I use:
mHttpClient.addResponseInterceptor(new HttpResponseInterceptor() {
public void process(final HttpResponse response,
final HttpContext context) throws HttpException,
IOException {
HttpEntity entity = response.getEntity();
Header encheader = entity.getContentEncoding();
if (encheader != null) {
HeaderElement[] codecs = encheader.getElements();
for (int i = 0; i < codecs.length; i++) {
if (codecs[i].getName().equalsIgnoreCase("gzip")) {
response.setEntity(new GzipDecompressingEntity(
entity));
return;
}
}
}
}
});
You might also want to look at SyncService.java from the Google I/O app.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…