I have using a function to successfully detect internet connectivity in Android 4.1 to 6.0 apps, by sending a ping. (Because, remember that being connected to WiFi or the mobile network doesn't guarantee by itself, that device has actual access to the internet.) My problem is that I discovered that for some reason, my code is not working in Android 4.3. Do you know how to fix this? or perhaps, do you know a better method to detect internet connectivity on all devices within Android versions 4.1 - 6.0?
//this function works perfectly!! except in Android 4.3 Jellybean
public boolean isOnline() {
Runtime runtime = Runtime.getRuntime();
try {
Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
int exitValue = ipProcess.waitFor();
if(exitValue==0)
app.logy("PING @K - ONLINE!!");
return (exitValue == 0);
} catch (IOException e){
e.printStackTrace();
app.logy("PING ERROR - OFFLINE");
return false;
}
catch (InterruptedException e){
e.printStackTrace();
app.logy("PING ERROR - OFFLINE");
return false;
}
}