Skip to content

Instantly share code, notes, and snippets.

@anis-campos
Created June 19, 2019 14:24
Show Gist options
  • Save anis-campos/0664a7d0bd1e1ff6a25415f3b9198d32 to your computer and use it in GitHub Desktop.
Save anis-campos/0664a7d0bd1e1ff6a25415f3b9198d32 to your computer and use it in GitHub Desktop.
Checking network connectivity on Android before API Level 29
class NetworkUtils(private val context: Context) {
fun isConnected(): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork: NetworkInfo? = cm.activeNetworkInfo
var result = false
if (activeNetwork != null) {
result = activeNetwork.isConnectedOrConnecting
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment