title: Check internet connection even if connected to wifi or 3G
body: <p>I need to check if there is internet connection even if the phone is connected to a wifi network or 3G. I have this code but it says only if connected to a network:</p>
  
  <pre><code>public class ConnectionDetector {
  
      private Context _context;
  
      public ConnectionDetector(Context context){
          this._context = context;
      }
  
      public boolean isConnectingToInternet(){
          ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
            if (connectivity != null) 
            {
                NetworkInfo[] info = connectivity.getAllNetworkInfo();
                if (info != null) 
                    for (int i = 0; i &lt; info.length; i++) 
                        if (info[i].getState() == NetworkInfo.State.CONNECTED)
                        {
                            return true;
                        }
  
            }
            return false;
      }
  }
  </code></pre>