Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created March 21, 2018 00:53
Show Gist options
  • Save cdmunoz/c76c22a1bbda075fad0af3f204beacc6 to your computer and use it in GitHub Desktop.
Save cdmunoz/c76c22a1bbda075fad0af3f204beacc6 to your computer and use it in GitHub Desktop.
class Utils @Inject constructor(private val context: Context) {
fun isConnectedToInternet(): Boolean {
val connectivity = context.getSystemService(
Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (connectivity != null) {
val info = connectivity.allNetworkInfo
if (info != null)
for (i in info.indices)
if (info[i].state == NetworkInfo.State.CONNECTED) {
return true
}
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment