android connectivity manager
val cm = getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
cm.registerDefaultNetworkCallback( object : ConnectivityManager.NetworkCallback() {
override fun onCapabilitiesChanged(network: Network, capabilities: NetworkCapabilities) {
super.onCapabilitiesChanged(network, capabilities)
val connected = capabilities.hasCapability(NET_CAPABILITY_INTERNET)
}
override fun onLost(network: Network) {
super.onLost(network)
}
override fun onAvailable(network: Network) {
super.onAvailable(network)
}
override fun onUnavailable() {
super.onUnavailable()
}
override fun onLosing(network: Network, maxMsToLive: Int) {
super.onLosing(network, maxMsToLive)
}
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
super.onLinkPropertiesChanged(network, linkProperties)
}
override fun onBlockedStatusChanged(network: Network, blocked: Boolean) {
super.onBlockedStatusChanged(network, blocked)
}
})