1

My main aim is to run a something like below from within an Android application:

$(normal mode)su
#(root mode) chmod 777 <some file>

But the problem here is as soon the shell changes from $ --> # the chmod command doesn't work.

Another way of achieving this is to make a shell script, place it in the Android /data directory, and run it manually. But how can I run it from within the Android application, making sure that when the shell changes ($--> #) the functionality remains intact?

One more way is to run my script using the script manager application.

Matthew Read
  • 1,365
  • 1
  • 30
  • 50

1 Answers1

0

Try this

Process suProcess = Runtime.getRuntime().exec("su");

    DataOutputStream os = 
        new DataOutputStream(suProcess.getOutputStream());

   **strong text**
    for (String Command : /*your commands*/)
    {
      os.writeBytes(Command + "\n");
      os.flush();
    }

    os.writeBytes("exit\n");
    os.flush();

user12295
  • 211
  • 1
  • 3
  • 4