How to check currently internet connection is available or not in android

This will tell if you’re connected to a network: ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); boolean connected = (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED); Warning: If you are connected to a WiFi network that doesn’t include internet access or requires browser-based authentication, connected will still be true. You will need this permission in your manifest: <uses-permission … 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

How to detect working internet connection in C#?

Just use the plain function System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() that return true of false if the connection is up. From MSDN: A network connection is considered to be available if any network interface is marked “up” and is not a loopback or tunnel interface. Keep in mind connectivity is not all, you can be connected to a local … Read more

What is the best way to check for Internet connectivity using .NET?

public static bool CheckForInternetConnection(int timeoutMs = 10000, string url = null) { try { url ??= CultureInfo.InstalledUICulture switch { { Name: var n } when n.StartsWith(“fa”) => // Iran “http://www.aparat.com”, { Name: var n } when n.StartsWith(“zh”) => // China “http://www.baidu.com”, _ => “http://www.gstatic.com/generate_204”, }; var request = (HttpWebRequest)WebRequest.Create(url); request.KeepAlive = false; request.Timeout = timeoutMs; … Read more

Detect if Android device has Internet connection

You are right. The code you’ve provided only checks if there is a network connection. The best way to check if there is an active Internet connection is to try and connect to a known server via http. public static boolean hasActiveInternetConnection(Context context) { if (isNetworkAvailable(context)) { try { HttpURLConnection urlc = (HttpURLConnection) (new URL(“http://www.google.com”).openConnection()); … Read more