Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Detect if Wifi Requires Browser Login

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?

like image 332
Nicholas Avatar asked Aug 14 '12 23:08

Nicholas


People also ask

How does Android detect Internet connection?

Android devices detect captive portals requesting a specific URL, that currently is http://connectivitycheck.gstatic.com/generate_204. If they receive a 204 response then there's connectivity. If they receive a 30x response, then there's a captive portal in the way.


1 Answers

See the "Handling Network Sign-On" section of the HttpUrlConnection documentation:

Some Wi-Fi networks block Internet access until the user clicks through a sign-on page. Such sign-on pages are typically presented by using HTTP redirects. You can use getURL() to test if your connection has been unexpectedly redirected. This check is not valid until after the response headers have been received, which you can trigger by calling getHeaderFields() or getInputStream().

They have a snippet of sample code there. Whether this will cover your particular WiFi AP, I can't say, but it is worth a shot.

like image 146
CommonsWare Avatar answered Oct 05 '22 14:10

CommonsWare