I'm trying to experiment the HttpURLConnection to get some XML from a server. This is the code I'm using:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String myConn = this.getString(R.string.myConnection);
HttpURLConnection httpConnection = null;
InputStream in = null;
try {
URL mySite = new URL(myConn);
URLConnection connection = mySite.openConnection();
TextView tv = (TextView)this.findViewById(R.id.myTextView);
httpConnection = (HttpURLConnection)connection;
in = httpConnection.getInputStream();
String myString = convertStreamToString(in);
tv.setText(myString);
} catch (IOException ex) {} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
httpConnection.disconnect();
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
On the emulator this code works and i can see the stream on the TextView...
On my device I can't see anything (3g connection)..
Did I miss something?
thanks