Last active
March 25, 2018 15:15
-
-
Save TommyPersson/3367fe3caaa455472ed6d630927ed4bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var connectivitySubscription: Disposable? = null | |
override fun onStart() { | |
super.onStart() | |
connectivitySubscription = observeBroadcasts(ConnectivityManager.CONNECTIVITY_ACTION) | |
.subscribe(this::onConnectivityChange) | |
} | |
override fun onStop() { | |
super.onStop() | |
connectivitySubscription?.dispose() | |
} | |
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