try {
String URLName = "http://www.sample.com";
String line,res = "";
HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((line = in.readLine()) != null){
res=res+line;
}
}
catch (Exception e) {
e.printStackTrace();
}
by the end, I get “” from res on my friend’s android 4.x
but it runs fine on my emulator
and when I use the browser on my friend’s phone to open the site: http://www.sample.com
then my app works again until we restart the phone
If it runs fine on your emulator(I assume the emulator runs on API Level 11<), but not on Android 4.x then I assume you are performing an heavy network task in your UI thread. Use an Asynctask to avoid that.