vindaaron
vindaaron

Reputation: 97

What permissions do I need to run a shell command programmatically in Android?

         try{
             Process process;
             process = Runtime.getRuntime().exec(command);
             BufferedReader in = new BufferedReader(new
                     InputStreamReader(process.getInputStream()));
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }

Upvotes: 4

Views: 7004

Answers (2)

devunwired
devunwired

Reputation: 63303

It depends on the command you wish to run, you may not need any. However, if your attempting to run a system level command you will need root access (not an Android permission). Running a platform command pretty much circumvents anything going on with Android permissions and is only affected by whether or not your linux user id has read/write/execute permission for the command you are issuing.

Runtime.exec() will also throw a SecurityException if you are not allowed to run a specific command and the exception will provide more details as to why in the specific case, so you should probably catch that in your try block also. You may also use Runtime.checkexec() to verify if you can run a certain command string before you actually attempt it.

Hope that Helps!

Upvotes: 5

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43108

I assume that no permissions are necessary here. But you can analyze the result of execution in order to understand were the binary get executed.

Upvotes: 0

Related Questions