I need to check the current internet availability. Since many of the old calls are deprecated I use the
ConnectivityManager.NetworkCallback()
approach with a callback. However, when implementing something like this:
private val connectivityCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
Log.debug("Available $network")
}
override fun onLost(network: Network) {
Log.debug("Lost $network")
}
}
the onAvailable is not working reliable.
This causes issues when working with WIFI and Cellular networks at the same time. When the users are deactivating wifi I get the callback for the lost network of the wifi. But I don not get an Available call for the cellular network. Thus my app is believing I have no internet.
What am I doing wrong?