【发布时间】:2016-03-26 21:30:06
【问题描述】:
如何计算来自 android 的 IP 地址的延迟/ping 时间(毫秒)。
我想在我的应用中实现这一点。 我已经尝试了以下代码,但它没有输出任何内容
private void executeCommand() throws IOException {
String pingResult=" ";
Runtime r=Runtime.getRuntime();
Process p=r.exec(new String[] {"ping", "-c 4", "www.google.com"});
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine;
Toast.makeText(getApplicationContext(), "Going loop", 1).show();
while((inputLine=in.readLine())!=null)
{
pingResult+=inputLine;
}
Toast.makeText(getApplicationContext(),pingResult, 1).show();
System.out.println(pingResult);
in.close();
}
【问题讨论】: