Run binary from with root Android Application Run binary from with root Android Application unix unix

Run binary from with root Android Application


I've answered this many times and helped others as well. Please try this:

Usage: Run(new String[]{"/system/bin/sh", "-c", "su"});public String Run(String[] cmd) {    StringBuffer theRun = null;    try {        Process process = Runtime.getRuntime().exec(cmd);        BufferedReader reader = new BufferedReader(                new InputStreamReader(process.getInputStream()));        int read;        char[] buffer = new char[4096];        StringBuffer output = new StringBuffer();        while ((read = reader.read(buffer)) > 0) {            theRun = output.append(buffer, 0, read);//output        }        reader.close();        process.waitFor();    } catch (IOException e) {        throw new RuntimeException(e);    } catch (InterruptedException e) {        throw new RuntimeException(e);    }        return theRun.toString();//return output}

Also, this link is helpful: http://www.stealthcopter.com/blog/2010/01/android-requesting-root-access-in-your-app/


I know my answer is late, but if you are still facing this issue, here is what I did. I also had to run a binary with root permission. I tried several things, like placing the binary in the /system/app folder, where the system apps run from and hence have root permission. But it did not work. So, I had to modify the su.c file and recompile the kernel, as mentioned in THIS site. If recompiling the kernel is not an option, you can try making the same change in a roottool (like busybox) and recompiling that. You can now use "busybox su -c" instead of just "su -c".