sg86-
sg86-

Reputation: 75

Android using Super User Permissions ? allowing access

im trying to find the method behind having superuser access on android devices. basically i want my app to be able to remove system files, and so asking the user if its ok after the app is launched like most other apps, and then what code exactly am i looking to use to perform these sorts of actions? cant find much on google

thanks in advance!

Upvotes: 6

Views: 10564

Answers (3)

Searene
Searene

Reputation: 27614

Here you can find a clear illustration about how to gain root permissions

Upvotes: 1

Blu Dragon
Blu Dragon

Reputation: 394

If the device is rooted, you can use the following code to gain access to a root shell:

    try
    {
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); 
        DataInputStream inputStream = new DataInputStream(process.getInputStream());

        outputStream.writeBytes(command + "\n");
        outputStream.flush();

        outputStream.writeBytes("exit\n"); 
        outputStream.flush(); 
        process.waitFor();
    }
    catch (IOException e)
    {
        throw new Exception(e);
    }
    catch (InterruptedException e)
    {
        throw new Exception(e);
    }

Where "command" is the command that you want to execute.

Upvotes: 10

Octavian Helm
Octavian Helm

Reputation: 39605

If I'm getting it right you want to grant your application root privileges. This is not possible with the standard Android image which is installed on the devices. The su command does not support changing to root.

You can however load a customized rooted ROM on your device other than that I'm afraid there is no solution.

Upvotes: 1

Related Questions