0

My problem is that my application have around 12-13 screen, and all of that uses internet to parse data. So if my application lost an internet connection, it should alert user with "no internet available" message.

Is there any built-in service or methods that check internet avilability in background and alert user if internet is not available?

richq
  • 55,548
  • 20
  • 150
  • 144
Nirav Bhandari
  • 4,550
  • 6
  • 32
  • 59
  • 1
    possible duplicate of [How to check internet access on Android? InetAddress never timeouts](http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts) – Kurtis Nusbaum Nov 15 '11 at 15:46

1 Answers1

2

You can use this function:

protected boolean isNetworkConnected() {
    Context ctx = this;
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo network = cm.getActiveNetworkInfo();
    if (network != null) {
        return network.isAvailable();
    }
    return false;
}
SERPRO
  • 10,015
  • 8
  • 46
  • 63
  • i know that..but my problem is that i want some background servicce which check continue sly for internet avilabilty and if not avilable alert message will be displayed..any idea,how to check it continuously? – Nirav Bhandari Nov 15 '11 at 15:54
  • 1
    Then add that to a service and broadcast the changes or save it in your SharedPreferences and add in your activities the Listener for SharedPreferences – SERPRO Nov 15 '11 at 15:57