求教如何在android 中调用ping命令 来获取发送和接受消息数目  多谢

解决方案 »

  1.   

    楼主:new Thread(new Runnable()
    {
         public void run(){       Thread.sleep();
           Update();
           }  
    });mHandler= new Handler()
    {
       @override
       public void handleMessage(Message msg){}
    }public void Update(){mHandler.sendMessage(mHandler.obtainMessage());
    }楼主,你看看这样可以吗?通过不断更新数据,设置个静态变量。去获取。
      

  2.   

    jni 调用 core里面的 ping ……数据重定向到某文件中保存 再通过jni返回给上层Java 显示 也可是直接打开log文件 回避java作个显示界面的繁琐过程
      

  3.   

    不要其他system call数据的话 也可以
      Runtime runtime = Runtime.getRuntime();
      Process p = runtime.exec("ping xxxxxxxxx -argv"); 
      

  4.   

      mBtnAction = (Button)findViewById(R.id.BTN_ACTION);
      mTxtContents = (EditText)findViewById(R.id.TXT_CONTENTS);  
      mBtnAction.setOnClickListener(this);  private void doAction() {
      try {   
      Runtime runtime = Runtime.getRuntime();
      System.out.println("hello");
      Process proc = runtime.exec("ping fr.yahoo.com -c 1"); // other servers, for example
      proc.waitFor();
      } catch (IOException e) {   
      e.printStackTrace();   
      } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }
      private void printText(String text) {
      mTxtContents.append(text);
      mTxtContents.append("\n");
      }
      

  5.   

    有试不过始终没有得到结果
    还有就是如何将ping的结果回现到 TxtContents里面?
    我才学没多久
      

  6.   

    得调用 adb shell的ping命令吧
      

  7.   


        private static final boolean pingIpAddr() {
            String mPingIpAddrResult;
         try {
                String ipAddress = "74.125.47.104";
                Process p = Runtime.getRuntime().exec("ping -c 1 -w 100 " + ipAddress);
                int status = p.waitFor();
                if (status == 0) {
                    return true;
                } else {
                    mPingIpAddrResult = "Fail: IP addr not reachable";
                }
            } catch (IOException e) {
                mPingIpAddrResult = "Fail: IOException";
            } catch (InterruptedException e) {
                mPingIpAddrResult = "Fail: InterruptedException";
            }
            return false;
        }
      

  8.   

    好了吗?我在模拟器可以ping 127.0.0.1 其他的ping不通 怎么回事啊?有大侠路过吗?
      

  9.   

    我用了10楼的方法,可是为什么总是不通,返回总是2 ?
    而在ADB里,通过命令却可以执行?
      

  10.   

    http://www.eoeandroid.com/thread-65869-1-1.html