Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get root permissions through the Android SDK?

Tags:

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?

like image 395
Rob Avatar asked Mar 14 '11 00:03

Rob


People also ask

How do I get permission to root my Android?

In most versions of Android, that goes like this: Head to Settings, tap Security, scroll down to Unknown Sources and toggle the switch to the on position. Now you can install KingoRoot. Then run the app, tap One Click Root, and cross your fingers. If all goes well, your device should be rooted within about 60 seconds.

What is SDK permission?

user-permission-sdk-23 specifies that the app that wants a particular permission is running on SDK version 23 or higher. It is used when you update your app to run SDK 23 elements and the users running a lower API which does not support the new elements. Android manifest - user permissions.

Can you root an Android emulator?

Please note that android emulators already are "rooted". You do not need to do anything to get a root adb shell, as it already runs as root by default.


1 Answers

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.

like image 123
Mohit Deshpande Avatar answered Sep 28 '22 01:09

Mohit Deshpande