Sunday, February 20, 2011

How to get root access and execute commands in your Android application ?

Well, I've tried executing several commands that required root access in my Android application (AutomateIt) and found several partial solutions online (especially this one), which helped me a lot but were still missing something to make them more robust and reusable.

Since I try making things very generic and easy to use, I constructed a class that handles most of the things required to execute commands from your Android application after getting root privileges. All you need to do is extend this class and implement one simple method that returns a list of all the commands you wish to execute (getCommandsToExecute).The class also provides a static service that can be used to determine whether the application has root access or not. Note that when calling the static service, it actually requests for root access and returns the result to that request.