0

I'm trying to create an app that uses the Runtime.getRuntime().exec() method to use the command-line in order to run some commands on an android phone. First, I need to get root access so I am doing:

Runtime rt = Runtime.getRuntime();
            String cmdString = "su";

            System.out.println(cmdString);
            Process pr = rt.exec(cmdString);

When I do this, my app asks the user to be granted root access. when the user accepts, it says the app has been granted root access but then the app completely freezes. When I try to run other commands like ls, they work fine.

coder4lyf
  • 927
  • 1
  • 17
  • 36
  • `su` doesn't give your application root access as such. Only the invoked `su` process gets root access, and your application can interact with the `su` process to do things. You can do this by writing a shell command to `pr.getOutputStream()`, and reading the result from `pr.getInputStream()`. This should be done asynchronously, as both may block. Close the output stream when done to let `su` exit. – that other guy Jun 18 '15 at 17:29
  • do you have any good resources that I can refer to? – coder4lyf Jun 18 '15 at 19:05
  • I couldn't find any good on-site resources, but [this post](http://stackoverflow.com/questions/8750660/android-su-permissions-how-to-use-them) should be enough to get started, even if it's not as general and robust as it could be. It starts the process ok, but neglects to read its output, close the input and wait for it to finish. – that other guy Jun 18 '15 at 19:25

0 Answers0