title: Android service to check internet connectivity?
body: <p>I want to create an Android service, which notifies the main activity whenever disconnects and when internet reconnects again. I have following function for checking internet connectivity:.</p>
  
  <pre><code>private boolean haveInternet(){
          NetworkInfo info=(NetworkInfo)((ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
  
          if(info==null || !info.isConnected()){
              return false;
          }
          if(info.isRoaming()){
              //here is the roaming option you can change it if you want to disable internet while roaming, just return false
              return true;
          }
          return true;
      }
  </code></pre>
  
  <p>But I want to know, how to use it in a service.</p>