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!