2012-03-29 64 views
0

我在Android編寫代碼,我需要一些文件的更改權限,我已經安裝Busybox的有許多命令,但在執行代碼時不執行任何操作。如何更改的權限與調用Runtime.getRuntime到文件()。exec的

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); 
} 
+0

也許這可以幫助[上紮根設備上執行CHMOD(http://stackoverflow.com/questions/4594071/android-how-can-execute-a-chmod-on-rooted-devides ) – Linus 2012-03-30 08:38:45

回答

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

描述代碼如何解決問題的簡短段落總是有用的。 – Ren 2013-03-14 10:09:38