I use this code to check Internet connection, and my application can't seem to access the internet from the emulator.
public boolean isConnectedToInternet() {
Runtime runtime = Runtime.getRuntime();
try {
Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
int exitValue = ipProcess.waitFor();
return (exitValue == 0);
} catch (IOException e) { e.printStackTrace(); }
catch (InterruptedException e) { e.printStackTrace(); }
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState){
...
if(isConnectedToInternet()) {
util.toast(authentication.this, "connected to internet");
} else {
util.toast(authentication.this, "not connected to internet");
}
}
Other internet access from the machine is working fine, and ping 8.8.8.8
from cmd gets replies.
Is there any way to find out what exactly is the problem?