在 Android 中以编程方式运行 shell 命令需要什么权限?
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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您想要运行的命令,您可能不需要任何命令。但是,如果您尝试运行系统级命令,您将需要 root 访问权限(而不是 Android 权限)。运行平台命令几乎可以规避 Android 权限所发生的任何情况,并且仅受您的 Linux 用户 ID 是否对您发出的命令具有读/写/执行权限的影响。
如果不允许您运行特定命令,
Runtime.exec()
也会抛出SecurityException
,并且该异常将提供有关特定情况下原因的更多详细信息,因此您可能也应该在您的try
块中捕获它。您还可以在实际尝试之前使用 Runtime.checkexec() 来验证是否可以运行某个命令字符串。希望有帮助!
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 aSecurityException
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 yourtry
block also. You may also useRuntime.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.