2
如何計算來自android的ip地址的延遲/ ping時間(以ms爲單位)。計算ping時間android
我想在我的應用程序中實現此功能。 我曾嘗試下面的代碼,但它不會做任何輸出
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();
}