7

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.

Community
  • 1
  • 1
MikkoP
  • 4,864
  • 16
  • 58
  • 106

1 Answers1

9

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).

bclymer
  • 6,679
  • 2
  • 27
  • 36