2012-03-29 16 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

関連する問題