I can't figure out how exactly to get a simple string from an url. I have tried several versions of this code:
String str = null;
try {
// Create a URL for the desired page
URL url = new URL("mysite.com/thefile.txt");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
Toast.makeText(getApplicationContext(), str, Toast.LENGTH_LONG).show();
With all the proper manifest permissions but can't get to return anything. My txt file just contains
www.google.com
and I can access it from the phone or computer in any browser. Any ideas?