title: Android root access script
body: <p>I need help with this script, can someone tell me what did I do wrong?
  I'm trying to make a root checker on startup.   </p>
  
  <ol>
  <li>Check write access   </li>
  <li>ReturnaAlert of no root   </li>
  <li>Exit on press exit (TO DO)   </li>
  </ol>
  
  <p>Here's the exact Java snippet I'm building   </p>
  
  <pre><code>{
          Process p;
      try
      { 
          //  Run root command
          p = Runtime.getRuntime().exec("su"); 
  
          // Attempt to write a file to system
          DataOutputStream os = new DataOutputStream(p.getOutputStream()); 
          os.writeBytes("echo \"Do I have root?\" &gt;/system/temporary.txt\n");
  
          // Close the stream
          os.writeBytes("exit\n"); 
          os.flush(); 
          try
          { 
              p.waitFor(); 
              if (p.exitValue() != 255)
              { 
                  // Code to run on ROOTED
                  //  NOTHING JUST GO FORWARD
              }
              else
              { 
                  // Code to run on NON ROOTED
  
              } 
          }
          catch (InterruptedException e)
          { {
              // TODO Code to run with interrupted exception
  
              }
          } 
      }
      catch (IOException e)
      { 
          // TODO Code to run in input/output exception
  
      }}}
  </code></pre>
  
  <p>The APK file is built <a href="https://my.pcloud.com/publink/show?code=kZ3XDSZla782IpIsWYTLD6Kf5r3bzBDxnvy" rel="nofollow">here</a> for testers.</p>
  
  <p>The root snippets source comment <a href="http://www.anddev.org/viewtopic.php?p=33450" rel="nofollow">here</a></p>