Runtime.getRuntime().exec执行cmd命令时权限不足的问题

cgz1211 2010-11-10 11:18:54
请问各位高手,用下面方法执行cmd命令的时候遇到权限不足的问题,如果在init.rc中添加
service runtime /system/bin/runtime
user root
group root
能否解决权限不足的问题?

public static boolean runRootCommand(String command) {
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "+e.getMessage());
return false;
}
finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
// nothing
}
}
return true;
}
}
...全文
1807 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cgz1211 2010-11-17
  • 打赏
  • 举报
回复
我想在应用程序中调用ifconfig等网络配置命令实现网络的配置,不知道各位有什么好的建议。因为ifconfig要root权限才能执行。
Sodino 2010-11-10
  • 打赏
  • 举报
回复
手机如果已经获取root权限的话,执行su会跳出超级权限访问是否允许。

如果没有root,权限不允许
DrSmart 2010-11-10
  • 打赏
  • 举报
回复
没root权限,执行su当然。。。

80,358

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧