2012-12-02 6 views
0

이 코드를 사용하여 textView에서 만든 규칙을 표시하려고합니다.iptables 안드로이드의 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(); 
             } 
           } 

문제는 그것이 그 수퍼 유저 권한이 부여되었음을 알려주지 만, BufferReader ..... help를 사용했지만 테이블이 TextView에 나타나지 않습니까?

답변

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; 
      } 
     } 

도움이되기를 바랍니다.