Skip to content

Instantly share code, notes, and snippets.

@shikto1
Last active May 10, 2022 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shikto1/35fc8cf5e8c3e5ecd3f3a8af24921f68 to your computer and use it in GitHub Desktop.
Save shikto1/35fc8cf5e8c3e5ecd3f3a8af24921f68 to your computer and use it in GitHub Desktop.
fun isInternetAvailable(context: Context): Boolean {
var isConnected: Boolean = false // Initial Value
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork: NetworkInfo? = connectivityManager.activeNetworkInfo
if (activeNetwork != null && activeNetwork.isConnected)
isConnected = true
return isConnected
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment