Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving an Android app root permission

Using adb.exe that comes with the Android SDK, I can get root access to an Android device. For testing purposes, I would like to give an Android app root permissions as well. I know that app is running under a particular account called app_68. Is there an adb shell command to add app_68 to the "root group"?

Thanks in advance for your comments/solutions.

like image 452
ytw Avatar asked Mar 05 '12 23:03

ytw


1 Answers

You need the superuser (su) binary to run your app as root user. For running as root implement this:

Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());

os.writeBytes("yourCommand\n");

os.writeBytes("exit\n");

os.flush();
os.close();
try { p.waitFor(); } catch (InterruptedException e) {}

If you get something like su: uid xxxx not allowed, then you need to update your su-binary using SuperSU.

Also see https://stackoverflow.com/a/26654728/4479004 if you want a fully detailed and working source.Just look at the code below:

Update: To get the result (the output to stdout), use:

like image 76
xdevs23 Avatar answered Sep 21 '22 17:09

xdevs23