How to check for unrestricted Internet access? (captive portal detection)

For reference, here is the ‘official’ method from the Android 4.0.1 AOSP code base: WifiWatchdogStateMachine.isWalledGardenConnection(). I am including the code below just in case the link breaks in the future. private static final String mWalledGardenUrl = “http://clients3.google.com/generate_204”; private static final int WALLED_GARDEN_SOCKET_TIMEOUT_MS = 10000; private boolean isWalledGardenConnection() { HttpURLConnection urlConnection = null; try { URL … Read more

Detect if the internet connection is offline?

Almost all major browsers now support the window.navigator.onLine property, and the corresponding online and offline window events. Run the following code snippet to test it: console.log(‘Initially ‘ + (window.navigator.onLine ? ‘on’ : ‘off’) + ‘line’); window.addEventListener(‘online’, () => console.log(‘Became online’)); window.addEventListener(‘offline’, () => console.log(‘Became offline’)); document.getElementById(‘statusCheck’).addEventListener(‘click’, () => console.log(‘window.navigator.onLine is ‘ + window.navigator.onLine)); <button id=”statusCheck”>Click … Read more

Android event for internet connectivity state change [duplicate]

very old post but i would like to share my receiver no need to put your hands on manifest or other boring resources 🙂 USAGE YOUR ACTIVITY: /* * You need to implement NetworkStateReceiverListener. * This interface is described inside the NewtworkStateReceiver class */ public class MyActivity implements NetworkStateReceiverListener { /* … */ private NetworkStateReceiver … Read more

Android: Internet connectivity change listener

Try this public class NetworkUtil { public static final int TYPE_WIFI = 1; public static final int TYPE_MOBILE = 2; public static final int TYPE_NOT_CONNECTED = 0; public static final int NETWORK_STATUS_NOT_CONNECTED = 0; public static final int NETWORK_STATUS_WIFI = 1; public static final int NETWORK_STATUS_MOBILE = 2; public static int getConnectivityStatus(Context context) { ConnectivityManager … Read more