Check data connection
suggest changePing a host to see whether it answers. A return code of 0 means this host replied. It does not prove every destination is reachable, and some networks block ICMP. The INTERNET permission is required, and ping must exist on the device.
public boolean isDataConnected() {
try {
Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 8.8.8.8");
int returnVal = p1.waitFor();
boolean reachable = (returnVal==0);
return reachable;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents