I have read this Answer About Getting Internet Connection Status in Android:
https://stackoverflow.com/a/22256277/4225644
But It doesn't work properly, for example if i have a network connection with no internet Access, this method takes too long time to return False:
public Boolean isOnline() {
try {
Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com");
int returnVal = p1.waitFor();
boolean reachable = (returnVal==0);
return reachable;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
How Can I decrease this Time to have a faster answer?