I am using the getActiveNetworkInfo
to get the network that the user is connected and using the isConnected
to verify if it is connected. I am doing this with the following code:
val connectivityManager = getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager?
val activeNetworkInfo = connectivityManager?.activeNetworkInfo
return activeNetworkInfo?.isConnected == true
The problem is that if the user is connected for example to a wifi that has no internet connection, the isConnected
returns true.
How can I verify if this network connection has internet connection?
I know that I can execute a request to some service to verify if the user is connected, but my intention is to show a banner for the user inside the app to notify him that he has no internet connection. So for example when he request something, I can notify the user that it will not work and don't show a loading and then an error message.
Keep pooling a service to verify the internet connection is not an alternative either way, it will not be efficient in terms of data and battery usage.