Skip to content

Instantly share code, notes, and snippets.

@tolmachevroman
Last active November 26, 2017 05:11
Show Gist options
  • Save tolmachevroman/8065b56dc7e17638fc0a16570f5614aa to your computer and use it in GitHub Desktop.
Save tolmachevroman/8065b56dc7e17638fc0a16570f5614aa to your computer and use it in GitHub Desktop.
Medium Post 3. Utils.hasConnection()
fun hasConnection(): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.activeNetworkInfo
return activeNetwork != null && activeNetwork.isAvailable && activeNetwork.isConnected
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment