Skip to content

Instantly share code, notes, and snippets.

@vishvendra01
Created June 22, 2015 13:23
Show Gist options
  • Save vishvendra01/3f5fef3213c3d9598355 to your computer and use it in GitHub Desktop.
Save vishvendra01/3f5fef3213c3d9598355 to your computer and use it in GitHub Desktop.
check whether internet connection available or not
/**
*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