Search code examples
androidandroid-internet

Check internet connection throughout my application


I'm working on Internet based app,so i need to monitor Internet Connection. link

I used this code in on create of mainActivity to check my internet connection it works fine.

public boolean isOnline() 
{  
ConnectivityManager cm = (ConnectivityManager) 
getSystemService(Context.CONNECTIVITY_SERVICE);  return 
cm.getActiveNetworkInfo().isConnectedOrConnecting();
}

But i need this monitoring should be done through out application. Where should i use this ? Any AsyncTask needed?


Solution

  • create a BroadcastReceiver to detect change in connection status. see Eric's answer here