Skip to content

Instantly share code, notes, and snippets.

@firecatmusic
Created August 20, 2019 04:59
Show Gist options
  • Save firecatmusic/beee342e9b7619f83c4f284ff79ba18f to your computer and use it in GitHub Desktop.
Save firecatmusic/beee342e9b7619f83c4f284ff79ba18f to your computer and use it in GitHub Desktop.
private var connectionReceiver: ConnectionReceiver? = null
override fun onStart() {
super.onStart()
connectionReceiver = ConnectionReceiver()
registerReceiver(connectionReceiver, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
}
override fun onStop() {
try {
unregisterReceiver(connectionReceiver)
} catch (e: IllegalStateException) {
e.printStackTrace()
}
super.onStop()
}
inner class ConnectionReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val isOnline = NetworkUtil.getConnectivityStatusString(this@Activity)
if (!isOnline) showDialogNoInternet(this@Activity)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment