code: private static boolean isInternetReachable()
      {
          try {
              final URL url = new URL("http://www.google.com");
              final HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection();
              urlConnect.setConnectTimeout(1000);
              urlConnect.getContent();
              urlConnect.disconnect();
          } catch (UnknownHostException e) {
              return false;
          } catch (IOException e) {
              return false;
          }
          return true;
      }
docs: Tries to retrieve some content, 1 second timeout.