0

I've been looking for help on the other questions, but can not find something, while in a review activity need internet connection, even with activated 3G but can not connect (have exceeded data use or firewall) tutorials or help I have found do not include that.

Sam
  • 7,252
  • 16
  • 46
  • 65
Loreln
  • 201
  • 3
  • 14
  • Are you getting any kind of error message? Tested other connection (e.g. Local connection) ? – David May 14 '13 at 02:32
  • could you check the ping (long ping = not accessible)? http://stackoverflow.com/questions/9062182/android-icmp-ping – Angel Koh May 14 '13 at 02:37
  • Im try check the ping right now, thanks, and @David im trying on my android device, im make a connection to mysql, but when i load the info on mysql and i dont have internet, its give me an error and close the app – Loreln May 14 '13 at 02:45

1 Answers1

1

I use this little function to detect Public Wifi redirects to sign on page. If this function returns false, it means you could not connect to the intended page despite having your 3G or Wifi on. With this you can show the user any page, for example a "No Internet Connection" page.

public boolean networkSignOn() {
    HttpURLConnection urlConnection = null;
    try {
        URL url = new URL("http://clients3.google.com/generate_204");
        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setInstanceFollowRedirects(false);
        urlConnection.setConnectTimeout(10000);
        urlConnection.setReadTimeout(10000);
        urlConnection.setUseCaches(false);
        urlConnection.getInputStream();
        return urlConnection.getResponseCode() == 204;
    } catch (IOException e) {
        Log.v("Walled garden check - probably not a portal: exception " + e, "");
        return false;
    } finally {
        if (urlConnection != null) urlConnection.disconnect();
    }
}
Munir Basheer
  • 162
  • 11