Created
June 19, 2019 14:24
-
-
Save anis-campos/0664a7d0bd1e1ff6a25415f3b9198d32 to your computer and use it in GitHub Desktop.
Checking network connectivity on Android before API Level 29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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