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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With