Mihir
Mihir

Reputation: 2074

Run adb shell command using android code

echo 0 > /sys/class/leds/button-backlight/brightness

The above command is working perfectly through adb shell.But when I try to run through my code there is no effect.Here is my code.

Process mSuProcess;
mSuProcess = Runtime.getRuntime().exec("su"); 
DataOutputStream mSuDataOutputStream = new DataOutputStream(mSuProcess.getOutputStream()); 
mSuDataOutputStream.writeBytes("echo 0 > /sys/class/leds/button-backlight/brightness \n");
mSuDataOutputStream.flush();
mSuDataOutputStream.close();

Please help me out on this.

Upvotes: 0

Views: 3731

Answers (2)

Alex P.
Alex P.

Reputation: 31666

The google original su binary checks for UID and only works if run by root or shell users. This is why it works when you run your command from adb shell interactively. In order to run this code from a java app you need to use a patched su binary - without UID checks.

Upvotes: 1

mn0102
mn0102

Reputation: 849

If the device which you are working on is not rooted then this may not work..

Upvotes: 2

Related Questions