Skip to content

Instantly share code, notes, and snippets.

@Debashis-Sinha
Created March 31, 2020 04:32
Show Gist options
  • Save Debashis-Sinha/f03f65ff245cfdb8576de00e3609a820 to your computer and use it in GitHub Desktop.
Save Debashis-Sinha/f03f65ff245cfdb8576de00e3609a820 to your computer and use it in GitHub Desktop.
private fun isOnline(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val n = cm.activeNetwork
if (n != null) {
val nc = cm.getNetworkCapabilities(n)
return nc!!.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment