Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetworkInfo.isConnected() returns true but no connection

I use gar's answer from this StackOverflow post to check internet connection availability. But, I'm not sure if it works correctly. If I turn off WiFi and mobile data connection and run the application, NetworkInfo.isConnected() returns true when there's no connection to the internet available.

What's wrong? If I turn airplane mode on, it correctly says no connection.

like image 233
MikkoP Avatar asked Oct 11 '13 18:10

MikkoP


1 Answers

There is sadly no way to determine if you have a internet connection with the current Android API. You can only determine if an adapter (WiFi, 3G, LTE, etc) is connected to a router.

That said, you can implement something that pings a known domain (www.google.com)? To determine in your connection is valid, but that will take time (a second or more on a bad connection).

like image 60
bclymer Avatar answered Oct 21 '22 09:10

bclymer