val cm = context.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val currentNetwork = cm.activeNetwork if (currentNetwork != null) { val caps = cm.getNetworkCapabilities(currentNetwork) val linkProperties = cm.getLinkProperties(currentNetwork) }
val cm = context.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager cm.registerDefaultNetworkCallback(object : ConnectivityManager.NetworkCallback() { overridefunonAvailable(network: Network) { Log.e(TAG, "The default network is now: " + network) }
overridefunonLost(network: Network) { Log.e(TAG, "The application no longer has a default network. The last default network was " + network) handle(null) }