Created
March 25, 2018 15:10
-
-
Save TommyPersson/9da00a66ca7b9da1a60ddaf5661dd315 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
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