2012-03-29 5 views
0

나는 안드로이드에 코드를 작성하고 일부 파일의 변경 권한이 필요하며 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

아마도 이것은 http://stackoverflow.com/questions/4594071/android-how-can-execute-a-chmod-on-rooted-devides ([루팅 기기 chmod를 실행] 도움) – Linus

답변

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

관련 문제