我想在app层面读取系统中存在的所有文件,就像是root explorer一样,他是怎么申请root权限的?

解决方案 »

  1.   

    追问:
    难道root explorer不是在app层面上做的这种操作?
      

  2.   

    root explorer怎么执行的我不知道  如果想要获得系统文件的话  要用到linux命令 
    public String exec() {
        String folder = "";
        try {
    Process process = Runtime.getRuntime().exec("su");
            DataOutputStream dataOut = new DataOutputStream(process.getOutputStream());
            InputStream dataIn = process.getInputStream();
            dataOut.writeBytes("ls");
            dataOut.flush();
            if(dataIn.read() != 0) {
                byte byteIn = (byte) dataIn.read();
        int available = dataIn.available();
        byte[] characters = new byte[available + 1];
        characters[0] = byteIn;
        dataIn.read(characters, 1, available);
        folder = new String(characters);
            }
            return folder;
        } catch (IOException e1) {
    e1.printStackTrace();
        } catch (InterruptedException e) {
    e.printStackTrace();
        }
    }