【问题标题】:How to change permissions to file with Runtime.getRuntime().exec如何使用 Runtime.getRuntime().exec 更改文件的权限
【发布时间】:2012-03-29 14:45:29
【问题描述】:

我正在android上写代码,我需要更改一些文件的权限,我安装了Busybox有很多命令,但是执行代码时什么都不做。

Process p = Runtime.getRuntime().exec("chmod 777 /data/app/XXX"); 
BufferedReader in = new BufferedReader(  
                                new InputStreamReader(p.getInputStream()));  
String line = null;  
while ((line = in.readLine()) != null) {  
                System.out.println(line);
}

【问题讨论】:

标签: android-ndk


【解决方案1】:
private boolean isSu() throws IOException, InterruptedException {
Process p;
    try {
    // Preform su to get root privledges
    p = Runtime.getRuntime().exec("su");

    // Attempt to write a file to a root-only
    DataOutputStream os = new DataOutputStream(p.getOutputStream());
    os.writeBytes("echo \"Do I have root?\" >/system/sd/temporary.txt\n");

        // Close the terminal
        os.writeBytes("exit\n");
    os.flush();
    try {
    p.waitFor();
    if (p.exitValue() != 255) {
        toastMessage("root");
        return true;
        } else {
        toastMessage("not root");
    }
    } catch (InterruptedException e) {
        toastMessage("not root");
        }
    } catch (IOException e) {
        toastMessage("not root");
    }

    return false;
}

【讨论】:

  • 一段描述发布的代码如何解决问题的简短段落总是有用的。
猜你喜欢
  • 2012-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-08
相关资源
最近更新 更多