Run a shell command as root on android?

眉间皱痕 提交于 2020-01-06 03:13:08

问题


I thought it would be cool to turn the hardware button lights on when my application needs user attention so the user could get an indicator when the screen is blanked. As it turns out, this requires root access (echo 1 > /system/class/leds/keyboard-backlight/brightness). I found a link on Stack (http://muzikant-android.blogspot.com/2011/02/how-to-get-root-access-and-execute.html) to a class which tests for root access but it fails on my Nexus-S.

Is there a way to run shell commands as root without having to root the device?

Thanks

Edit: this is the error I'm getting from logcat 11-15 12:34:19.889: D/ROOT(2029): Root access rejected [java.io.IOException] : Error running exec(). Command: [su] Working Directory: null Environment: null


回答1:


If your phone has root access then you can fire shell scripts using Process and Runtime class..




回答2:


The reason it fails it because your phone needs to be rooted.

See the Wikipedia entry for Rooting (Android OS).

It would be a major security flaw if any app on any phone could take root and do anything.



来源:https://stackoverflow.com/questions/8141235/run-a-shell-command-as-root-on-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!