How can I get root permissions through the Android SDK?

Rob picture Rob · Mar 14, 2011 · Viewed 72.3k times · Source

I'm learning Android programming, and I want to make an application which has to run as root. The logical thing would be to add a root permission in the Android Manifest.

I saw this link in the documentation, and especially noted the FACTORY_TEST permission:

public static final String FACTORY_TEST

Since: API Level 1

Run as a manufacturer test application, running as the root user. Only available when the device is running in manufacturer test mode. Constant Value: "android.permission.FACTORY_TEST"

Is that the best way?

If it's not possible using the SDK, how can I make a "root" application work?

Answer

Mohit Deshpande picture Mohit Deshpande · Mar 14, 2011

What you need to do is something like:

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

That causes SuperUser to show, which lets you either Allow or Block it from root access. This approach might not work if the user is not rooted. Here is a way you can test it.