开发者

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();
         }


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜