sami rahimi sami rahimi - 1 month ago 8
Android Question

time of ping to google for check internet availability

i really need help
i try this code but when internet is okay there is no problem but when the device is is connected to the wifi but there is not available internet it answer need a lot of time and its too slow
how can i reduce that time?

public Boolean isOnline() {
try {
Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1");
int returnVal = p1.waitFor();
boolean reachable = (returnVal==0);
return reachable;
} catch (Exception e) {
// TODO Auto-generated catch block
return false;

Answer Source

You can set the default timeout for ping using ping -c 1 -W 1

This sets the timeout to 1 sec. The default timeout is 4 seconds.