title: Check for Active internet connection Android
body: <p>I am trying to write a part in my app that will differentiate between an Active Wifi connection and an actual connection to the internet.  Finding out if there is an active Wifi connection is pretty simple using the connection manager however every time I try to test if I can connect to a website when the Wifi is connected but there is no internet connection I end up in an infinite loop.<br>
  I have tried to ping google however this ends up the same way:</p>
  
  <pre><code>Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com");
  int returnVal = 5;
  try {
      returnVal = p1.waitFor();
  } catch (InterruptedException e) {
      e.printStackTrace();
  }
  boolean reachable = (returnVal==0);
  return reachable;
  </code></pre>
  
  <p>I also tried this code:</p>
  
  <pre><code>if (InetAddress.getByName("www.xy.com").isReachable(timeout))
  {    }
  else
  {    }
  </code></pre>
  
  <p>but I could not get isReachable to work.</p>