Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run android program as root

Tags:

android

root

Is it possible to run my program as root? I know how to run command-line native utils, but how to run Java program as root?

like image 364
artem Avatar asked Feb 08 '12 13:02

artem


People also ask

How to run app as root Android?

To run as root you have to use the command line, because that's the only way you interact directly with the linux kernel. You can however use the command line to copy your app to the /system/app/ directory, and then you have the same permissions as system apps. Also, check out RootTools .

Can I make Android app using only Java?

Ofcourse you can,most android apps are made of java. Import applet or java swing and you can make what you want.

Can you make Android apps in C?

Can I make Android Apps in the C language? Google offers the native development kit (NDK) that uses native languages like C and C++ for Android development. But you can't build an entire Android app with C or C++. You need to learn Java.


1 Answers

This will work for you:

try {
    Process process = Runtime.getRuntime().exec("su");
    process.waitFor();
} catch (IOException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
}

You could use this for a command:

exec(new String[] { "su", "-c", COMMAND });

Best wishes, Tim

like image 106
Tim Avatar answered Sep 28 '22 00:09

Tim