Skip to content

Instantly share code, notes, and snippets.

@remylavergne
Created March 18, 2020 20:49
Show Gist options
  • Save remylavergne/e625bb75cdb13eb0ea645e20383804a2 to your computer and use it in GitHub Desktop.
Save remylavergne/e625bb75cdb13eb0ea645e20383804a2 to your computer and use it in GitHub Desktop.
[Android] Internet connectivity
fun isInternetAvailable() {
try {
val command = "ping -c 1 google.com"
if (Runtime.getRuntime().exec(command).waitFor() == 0) {
viewAction.onNext(LauncherAction.InternetAvailable)
} else {
viewAction.onNext(
LauncherAction.NoNetwork(
R.string.launcher_error_no_network_title,
R.string.launcher_error_no_network_message
)
)
}
} catch (e: InterruptedException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment