Hey everyone,
For those of you who want to do stuff with web POST and GET methods and need some help getting the response body of your HttpResponse objects, this post is for you!
public static String getResponseBody(HttpResponse response) { String response_text = null; HttpEntity entity = null; try { entity = response.getEntity(); response_text = _getResponseBody(entity); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { if (entity != null) { try { entity.consumeContent(); } catch (IOException e1) { } } } return response_text; } public static String _getResponseBody(final HttpEntity entity) throws IOException, ParseException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } InputStream instream = entity.getContent(); if (instream == null) { return ""; } if (entity.getContentLength() > Integer.MAX_VALUE) { throw new IllegalArgumentException( "HTTP entity too large to be buffered in memory"); } String charset = getContentCharSet(entity); if (charset == null) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } Reader reader = new InputStreamReader(instream, charset); StringBuilder buffer = new StringBuilder(); try { char[] tmp = new char[1024]; int l; while ((l = reader.read(tmp)) != -1) { buffer.append(tmp, 0, l); } } finally { reader.close(); } return buffer.toString(); } public String getContentCharSet(final HttpEntity entity) throws ParseException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } String charset = null; if (entity.getContentType() != null) { HeaderElement values[] = entity.getContentType().getElements(); if (values.length > 0) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } return charset; }Basically, all this is just complicated code for getting the CharSet of your HttpResponse entity, and then creating a buffer that slowly makes the response string one char at a time. Besides that everything else seems self explanatory, but let me know if you have questions and I’ll do my best to answer them.
Happy coding.
- jwei
A tipster at Gizmodo has leaked some details to the world about the new ‘Gooogle Phone’ AKA the Nexus One. Pricing has been released and it looks like this may be the official price. So the phone is manufactured by HTC, will work on any GSM network, (3G only on T-Mobile) and will be sold by Google!? Here are the details we’ve got so far:
Today I found that a new music download service is available for Android called Mewbox. It is very similar to the ITunes music store. Which is what Android has been waiting for. The great thing about Mewbox is that it is DRM-Free, and what this means you could lets say download a song from your android device and then put it on a cd with no problems.Unfortunately Mewbox is still in beta, but holds great promise. You can download this incredible software threw there website for Android devices or the ARCHOS 5. I personally am very excited to see the development with Mewbox and where it will go. We as Android users hope that it will hold up against the Giant that is ITunes…Below you will see what the people over at Mewbox have to say about the development of MewBox, and make sure that you check out Mewbox
I’ve been fine with the Hero battery to date although my useage is probably on the light side. I never use 3G during the day and one of the first things I do with any new device is look for the settings to switch it to 2G only. I also turn off anything to do with GPS as I very rarely use apps that need it. I do however tend to switch on wifi when I get back in the evening and leave it on for a couple of hours, in case I am browsing through the Android Marketplace or need to download any application updates.





You have 2 basic requirements for this “hack”
1. Phone MUST be ROOTED!!!
2. MUST be a True Type font or your phone won’t read it and you’ll have a $500 PaperWeight =D




Just when you thought there were no new breakthroughs to be had in search marketing … along comes Google Goggles. It’s a new “visual search” application focusing on computer vision for mobile phones, currently in development and testing at Google Labs. An early version has already been unveiled by the Goggles product development team and been released to Android mobile users.
Our gadget worlds are getting more and more cluttered with cables. When I look at my desk now it’s just a complete mesh of cables. Each cable requires a separate plug which is really frustrating. Then I saw the Kensington 4 port USB charger plug. 





I havn’t gotten to really push this app yet but from what I see so far this is the app I really needed. So far my only little hiccups have been my email coming a bit late. It has only happened a couple of times but it may be my server and not the app. This is by far the most expensive app I have purchased But so far seems like it was worth every penny. Everyone who uses corporate email should at least give the 5 day trial a shot. I don’t think you will regret it.