Skip to content

Instantly share code, notes, and snippets.

@nisrulz
Created July 31, 2022 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisrulz/ffe76f40284bb35828640c1ed7db79cd to your computer and use it in GitHub Desktop.
Save nisrulz/ffe76f40284bb35828640c1ed7db79cd to your computer and use it in GitHub Desktop.
Check if Internet is available in Android
private fun isInternetAvailable(): Boolean {
return try {
val timeoutMs = 1500
val sock = Socket()
val sockaddr = InetSocketAddress("8.8.8.8", 53)
sock.connect(sockaddr, timeoutMs)
sock.close()
true
} catch (e: IOException) {
false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment