I'm developing an android app, and would like to check if a website or a URL is active
I'm developing an android app, and would like to check if a website or a URL is active
The verification can be done using Android's own REST APIs, making a GET call from a URL and waiting for a Response, from that Response you make the logic on top of the Status Code you receive.
One of the Android REST APIs - link
Another alternative is to use the Java API itself to check, but it will be limited to the package API java.net
Ex:
public int getStatusCode(String urlPath) {
try {
URL url = new URL(urlPath); // http://www.seusite.com.br
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
return conn.getResponseCode();
} catch (IOException e) {
throw new RuntimeException(e);
}
}