Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
override fun onCreate(savedInstanceState: Bundle?) {
subscribeToBroadcastsOnLifecycle(ConnectivityManager.CONNECTIVITY_ACTION, this::onConnectivityChange)
private fun onConnectivityChange(intent: Intent) {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val isConnected = connectivityManager.activeNetworkInfo?.isConnected ?: false
Log.i("MainActivity", "isConnected = $isConnected")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.