I am writing android code to ping to the server. But the problem is that I can ping only to the localhost serve. When I try to ping external server or host like google.com the code doesnot work.
package com.ping;
import java.io.*;
import android.app.*;
import android.os.Bundle;
import android.widget.*;
public class MainActivity extends Activity
{
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text= (TextView)findViewById(R.id.pingview);
start();
}
protected boolean start()
{
try
{
Runtime runtime1 = Runtime.getRuntime();
Process proc = runtime1.exec("ping -c 1 202.51.67.57");
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String input;
while((input=reader.readLine())!=null)
{
text.setText(input+"\n");
}
}
catch (IOException e)
{
e.printStackTrace();
System.out.println(" Exception:"+e);
}
return false;
}
}