title: android emulator root access
body: <p>I need to execute a C program in my App by simply adding the executable to the android project and building the .apk. Then I try to execute the program in my application like this:</p>
  
  <pre><code>    Process result = Runtime.getRuntime().exec("su");
      String cmd = "PROGRAM_NAME";
  
      DataOutputStream dos = new DataOutputStream(result.getOutputStream());
      DataInputStreamdis = new DataInputStream(result.getInputStream());
  
      dos.writeBytes(cmd + "\n");
      dos.writeBytes("exit\n");
      dos.flush();
  </code></pre>
  
  <p>I know I need root access to do this so I installed Superuser.apk but that didn't work. Is there another possible way to do this? Btw the code is not fully extended it should just give a look at the way the program should be executed
  I'm running the emulator with Android 4.2.1</p>
  
  <p>Edit:
  Checking root permission first with</p>
  
  <pre><code>         Process suProcess = Runtime.getRuntime().exec("su");
  
           DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
           DataInputStream osRes = new DataInputStream(suProcess.getInputStream());
  
           if (null != os &amp;&amp; null != osRes) {
               os.writeBytes("id\n");
               os.flush();
               String currUid = osRes.readLine();
               boolean exitSu = false;
               if (null == currUid) {
                   Log.d("ROOT", "Can't get root access or denied by user");
              }
  </code></pre>