I have found source code that gives an opportunity to run a shell command from the app, and, as I can understand, returns a string with the executed command result:
I have tried to execute "ping -c 3 www.google.com", but the given method returns "Error: null". The way I execute the command is:
ShellCommand cmd = new ShellCommand();
CommandResult r = cmd.sh.runWaitFor("ping -c 5 www.google.com");
String text;
if (!r.success()) {
text = "Error:\n" + r.stderr;
}
else {
text ="Ping test results:\n" + r.stdout;
}
log(text);
Where is the problem?
You have probably solved this by now. But telling you you shouldn't do it seemed like no answer to me. Obviously if the ping command doesn't exist you can't call it and you can handle the error. But if it does, wow!
Here is a way to do it. Works on the emulator 2.1 anyway. The emulator likes to be started after you have a good Internet connection though. If you start the emulator and change your connection somehow, it may not work after that. I didn't need any permissions to do it either on the emulator.
It's different from yours anyway and needs to be put somewhere besides the create block, but...
Do you have Internet permission for your app? And is the device connected to the Internet? Is there any output in the Logcat?
This question shows a one method you could use to ping from Java, without needing to run the shell command.