Here I am going to tell you how can you execute shell  script with super user permission from  android application.

Hmm… why do you need this at all ???

Hack the phone

Access the low level hardware

hm… hm… do whatever your instinct says !!

Understanding SU

Setup android sdk. now open shell  by

adb shell



SU is a process which runs with special permissions. when you type su , the  process starts and then you need to  type  shell command which you want  to execute from the console  like  “reboot” ,”del”, “echo 1 > sys/platform/lcd/enabled” ,”mount”.

Note that ” su reboot ” does not work because su does not take command line argument as process name to execute.

So basically what su does is it reads the command from command prompt and then creates child process ,executes it .

Basic Idea.

So the basic idea is when we  execute su  process  from the android application ,we  need to pass shell command or shell script to su process and then we need to stop su  by sending “exit” as we do with command prompt.

  Process p=Runtime.getRuntime().exec(“su”);

This  line starts su process. We can’t do “su reboot” . You know why :).  Now we have to send command name to  su process. when we do it  from shell  ,su reads  from some input stream.

  DataOutputStream  stream=new DataOutputStream(p.getOutputStream());

we have stream object which is connected to the input stream of process su . check out the following code.


stream.writeBytes(“exit \n”);


Reference: Gscript

Download source code and play with it. This project contains additional feature likes  how to read data from native process and use it in your application.