0

我想使用此代码显示我在 textView 中创建的规则;

.....................................

                  public void show(View btn) throws IOException{

                 Show(tv);
                   }


        public final void Show(TextView tv) throws IOException{
            Process Q =Runtime.getRuntime().exec("su -c iptables -L INPUT 1 -n -v --line-numbers ");


             String pingResult="";
            BufferedReader in = new BufferedReader(new
                    InputStreamReader(Q.getInputStream()));
                    String inputLine;

                    while ((inputLine = in.readLine()) != null) {

                           tv.setText(pingResult+="\n"+inputLine+"\n");

                    }
                    in.close();
                                        } 
                                }

问题是它告诉我授予了超级用户权限,但表格没有出现在 TextView 中,即使我使用了 BufferReader ..... 帮助?

4

1 回答 1

0

使用此代码部分,我会执行您需要的相同操作,但会列出目录并读取输入。尝试使用此代码更改 getRuntime().exec 命令。

private String[] GetAppFiles() throws IOException
    {
        int BUFF_LEN =2048;
        Process p = Runtime.getRuntime().exec(new String[]{"su", "-c", "system/bin/sh"});
        DataOutputStream stdin = new DataOutputStream(p.getOutputStream());
        //from here all commands are executed with su permissions
        stdin.writeBytes("ls " + CurrentApkPath + "\n"); // \n executes the command
        InputStream stdout = p.getInputStream();
        byte[] buffer = new byte[BUFF_LEN];
        int read;
        String out = new String();
        //read method will wait forever if there is nothing in the stream
        //so we need to read it in another way than while((read=stdout.read(buffer))>0)
        while(true){
            read = stdout.read(buffer);
            out += new String(buffer, 0, read);
            if(read<BUFF_LEN){
                //we have read everything
                break;
            }
        }

我希望它对你有帮助。

于 2012-12-03T12:45:50.140 回答