I'm new to android and I'm trying to figure out how to get the contents of a URL as a String. For example if my URL is http://www.google.com/ I want to get the HTML for the page as a String. Could anyone help me with this?
+3
A:
From the Java Docs: http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html
URL yahoo = new URL("http://www.yahoo.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
Instead of writing each line to System.out, just append it to a string.
Drew
2010-01-16 01:30:06
Thanks, I tried that before and I just realized my problem: I forgot to give it internet permissions...
2010-01-16 01:54:55
If you post code examples which seem to be doing the right thing, it gives everyone else a chance to figure out what else could be causing the problem (like your permission issue).
Drew
2010-01-16 02:10:48