简体   繁体   中英

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.

如果您正在使用的设备没有植根,则可能无法正常工作。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM