1

I'm developing an app that needs internet connection to get informations from a sql database. I wrote a method to verify if the phone is currently connected to internet:

public static final boolean isOnLine(Context context) {
      ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

      if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) {
        return true;

      } else {
        return false;
      }
}

But what is the best way to send an alert when the internet connection is lost? Do I need to use a broadcast receiver somehow?!

Thanks!

MataMix
  • 3,276
  • 10
  • 39
  • 58

1 Answers1

3

Yes Broadcast Receiver will be adequate way to know when the internet connection is lost...and here is one similar question asked LINK

Hope this help!!!

Community
  • 1
  • 1
Gopal
  • 1,719
  • 12
  • 13