NetworkInfo.isConnected () returns true, but no connection

I am using gar answer from https://stackoverflow.com/a/166268/212 to check the availability of an internet connection. But I'm not sure if it works correctly. If I turn off Wi-Fi and mobile data connection and run the application, NetworkInfo.isConnected() will return true if there is no Internet access.

What happened? If I turn on airplane mode, it doesnโ€™t correctly speak about the connection.

+6
source share
1 answer

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

However, can you implement something related to a well-known domain (www.google.com)? To determine in your connection is valid, but it will take time (a second or greater value for a bad connection).

+9
source

Source: https://habr.com/ru/post/955801/


All Articles