【问题标题】:iptables Rules show in textView in android;iptables 规则显示在 android 的 textView 中;
【发布时间】:2012-12-02 12:58:14
【问题描述】:

我想显示我在 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 .....帮助?

【问题讨论】:

    标签: android textview runtime execution iptables


    【解决方案1】:

    有了这个代码部分,我会做同样的事情,但会列出一个目录并读取输入。尝试使用此代码更改 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;
                }
            }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 2012-08-31
      • 2013-05-06
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-26
      • 2014-03-13
      相关资源
      最近更新 更多