Mega Code Archive

 
Categories / Android / Network
 

Is Http Url Available

//package net.bible.service.common; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; // class CommonUtils {   public static boolean isHttpUrlAvailable(String urlString) {     HttpURLConnection connection = null;     try {       // might as well test for the url we need to access       URL url = new URL(urlString);       connection = (HttpURLConnection) url.openConnection();       connection.setConnectTimeout(3000);          connection.connect();       boolean success = (connection.getResponseCode() == HttpURLConnection.HTTP_OK);          return success;     } catch (IOException e) {          return false;     } finally {       if (connection != null) {         connection.disconnect();       }     }   } }