Coding for Mobile Platforms

Random thoughts, sometimes relevant to mobile programming.

  • Mobile Coder

  • Subscribe to Mobile Coder and receive notifications of new posts by email.

    Join 183 other followers

Archive for March, 2010

Grabbing URL’s on Android

Posted by error454 on 03/24/2010


If you are using URL.openStream() and wondering why it fails half the time, stop.

Start using HttpClient, HttpGet and HttpResponse

String address = "http://www.somesiteofinterest.com";

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();

request.setURI(new URI(address));
HttpResponse response = client.execute(request);

BufferedReader in = new BufferedReader(
					new InputStreamReader(
						response.getEntity().getContent()
					));

Posted in Android | Tagged: , | 1 Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 183 other followers

%d bloggers like this: