Created
June 22, 2015 13:23
-
-
Save vishvendra01/3f5fef3213c3d9598355 to your computer and use it in GitHub Desktop.
check whether internet connection available or not
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
/** | |
*Check internet connectivity by ping | |
*/ | |
public Boolean isOnline() { | |
try { | |
p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com"); | |
int returnVal = p1.waitFor(); | |
boolean reachable = (returnVal == 0); | |
if (reachable) { | |
System.out.println("Internet access"); | |
return reachable; | |
} else { | |
System.out.println("No Internet access"); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} finally { | |
p1.destroy(); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment