Does anyone know how to programatically detect in Android that wifi is unreachable? I've got an app running where I am able to easily detect type of network connection and whether is on or not (NetworkInfo class), but I can't detect that wifi is ON, but I am out of reach on the other side of building, so there is no internet. Network info keeps on saying that type of network is WIFI, isConnected = true, getDetailedState = CONNECTED, so these don't help me.
Asked
Active
Viewed 1,365 times
2
-
What do you mean by "wifi is on but unreachable?" Do you mean that you're connected to a network but can't send any data through it or that the wifi is on but there are no networks to connect to? – Catherine Apr 18 '13 at 09:05
-
yes, I mean that I switched WIFI ON on my phone and then walked far away from router, so I can't browse web pages, send data, etc... in this case, NetworkInfo still reports CONNECTED. I am using this code: `ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo();` – MartinC Apr 18 '13 at 09:17
-
You could possibly try detecting it by pinging a server and seeing if the ping times out? – Catherine Apr 18 '13 at 09:33
-
Hello. Have you solve the problem? That is we can connect to the router through wifi, but the connection between router and internet is broken. How can you detect this condition? – Yeung Apr 02 '20 at 06:00
1 Answers
0
Detect WIFI is connected or on. If wifi is not connected to any INTERNET connection then display message that "WIFI is unreachable or no INTERNET connection.
"
For checking WIFI is connected use following code.
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWifi.isConnected()) {
// Do whatever
}

Hardik Joshi
- 9,477
- 12
- 61
- 113
-
thanks, but this doesn't work. This is the situation which I've got already. mWifi reports CONNECTED. Problem is as I have described that I am out of reach, even though my Wifi functionality (or have to put it) is switched ON. – MartinC Apr 18 '13 at 09:26
-
-
that's what I do. I call it in a moment when I am out of reach (wifi icon is just a little dot) and inspect the logs. – MartinC Apr 18 '13 at 09:31
-
thanks, looks like signal strength is the one to monitor/detect in this case. – MartinC Apr 18 '13 at 10:22