Android - Detect if Wifi Requires Browser Login

Viewed 12943

My university has an open wifi access point, however it requires you to enter your e-mail before it allows you to use the web. My problem is that the Wifi is stupid in that it seems to drop my connection and force me to enter my e-mail again every 10 minutes.

I wanted to create my own app that I can use to automatically do this step for me, but I cannot seem to find any documentation for a nice and easy way to detect if a Wifi access point has a browser login page. Is there a way in Android to get this information, or is it just to see if my connection to something is always redirected to 1.1.1.1?

5 Answers

I used the following code using google's 204 endpoint.

 private boolean networkAvailable() {

        ConnectivityManager mManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        if(mManager != null) {
            NetworkInfo activeNetwork = mManager.getActiveNetworkInfo();
            if(activeNetwork== null || !activeNetwork.isConnectedOrConnecting()){
                return false;
            }
        }

        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url("http://clients1.google.com/generate_204")
                .build();
        try {
            Response response = client.newCall(request).execute();
            if(response.code() != 204)
                return  false; // meaning it either responded with a captive html page or did a redirection to captive portal.
            return true;
        } catch (IOException e) {
            return true;
        }
    }

Many applications including Google Chrome use http://clients1.google.com/generate_204 to verify that the the connection is not locked under captive portal.

Related