Created
March 18, 2020 20:49
-
-
Save remylavergne/e625bb75cdb13eb0ea645e20383804a2 to your computer and use it in GitHub Desktop.
[Android] Internet connectivity
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
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