2
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: www.sample.com then my app works again until we restart the phone

sum
  • 23
  • 3

1 Answers1

0

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.

Ahmad
  • 69,608
  • 17
  • 111
  • 137
  • actually my app runs that part of script just to get the newest version number in the res(variable) from a file at my site so my app can tell if the user already got the latest update – sum Dec 08 '12 at 12:47
  • Seems to be a little misunderstanding here; in recent versions of android ANY network access (extensive or trivial) is prohibited on the UI thread. It will result in an exception, which you are catching, but should be in the logcat since you are printing it. Please post the logcat if you are not figuring this out. – Chris Stratton Dec 08 '12 at 15:03