URL is invalid, or my country is blocked
put this BEFORE onCreate():
private TextView outtext;
private String HTML;
And add lines between comments into onCreate like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*FROM HERE*/
outtext= (TextView) findViewById(R.id.textview1); //change id if needed!!!
try {
getHTML();
} catch (Exception e) {
e.printStackTrace();
}
outtext.setText("" + HTML);
/*TO HERE*/
}
now this is the method you will use to download content:
private void getHTML() throws throws ClientProtocolException, IOException
{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://www.weather.noaa.gov/pub/data/observations/metar/stations/KORD.txt"); //URL!
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = null;
while ((line = reader.readLine()) != null) {
result += line + "\n";
HTML = result;
}
}
You also need to set permission in AndroidManifest.xml to use internet:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Also this is NOT the best way to do this. When you open your app it will freeze until it loads from website, so you should use AsyncTask to help you out there.