hi~ 大大们,请问有API可疑获取系统路由表信息吗?或者是否可以通过Runtime.getRuntime().exec("busybox route")之类的操作来读取?
怎么实现会简单些呢?

解决方案 »

  1.   

    可以使用busybox route
    try {
        // Executes the command.
        Process process = Runtime.getRuntime().exec("busybox route");
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        int read;
        char[] buffer = new char[4096];
        StringBuffer output = new StringBuffer();
        while ((read = reader.read(buffer)) > 0) {
            output.append(buffer, 0, read);
        }
        reader.close();
        // Waits for the command to finish.
        process.waitFor();    
        return output.toString(); //获得输出
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
      

  2.   

    谢谢你提供的方案,我使用这个方法的时候,碰到如下异常:06-30 05:35:05.182: ERROR/AndroidRuntime(327): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.David/com.android.David.LogTest1Activity}: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null
    06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.io.IOException: Permission denied请问这个操作需要什么permission呢?
      

  3.   

    我试过可以获取得到 不用什么权限 你直接adb shell busybox route有显示吗?
      

  4.   

    呃。我试了一下, device上可以成功,但是用Emulator就报了上面的exception.不过问题算是解决啦。非常感谢!