title: How to detect when WIFI is connected to internet?
body: <p>I am building an Android app and I use the code below to detect whether there is a network connection.  It works well and detects both mobile and WIFI networks.  </p>
  
  <p>My problem is how to detect an actual internet connection.  The code below returns true when connected to WIFI however the WIFI might not necessarily be connected to the Internet.</p>
  
  <p><em><strong>The code</em></strong></p>
  
  <pre><code>    protected boolean checkInternetConnection() {     
      ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);  
      // test for connection     
      if (cm.getActiveNetworkInfo() != null             
              &amp;&amp; cm.getActiveNetworkInfo().isAvailable()             
              &amp;&amp; cm.getActiveNetworkInfo().isConnected()) {
  
          return true;
  
          } 
      else {               
          return false;
  
          } 
  
  } //end checkInterneConnection method
  </code></pre>
  
  <p>Thanks for your time.</p>
  
  <p>Mel</p>