title: Check HTTP connection to a URL (Android)
body: <p>I am trying to check a connection to a URL using HTTP in an app...</p>
  
  <p>Process: </p>
  
  <p>User clicks buttons, app sends a get request and then if successful it will return true, else false.</p>
  
  <pre><code> final Button mbutton = (Button) findViewById(R.id.httpcheck);
      mbutton.setOnClickListener(new View.OnClickListener(){
          public void onClick(View v){
  
              public boolean isConnectedToServer(String url, int timeout) {
                  try{
                      URL myUrl = new URL("http://www.google.co.uk");
                      URLConnection connection = myUrl.openConnection();
                      connection.setConnectTimeout(timeout);
                      connection.connect();
                      return true;
                  } catch (Exception e) {
                      return false;
                  }
              }
  
          }
      });
  </code></pre>
  
  <p><img src="https://i.gyazo.com/dcf4e68ac5c4cfeae53a900654aef1ad.png" alt="Example"></p>