app发送cmd命令

来源:互联网 发布:四川房卡麻将源码 编辑:程序博客网 时间:2024/05/01 05:42

首先,要确保你手机是已root的(root使用KingRoot或者别的都行)

/*

*str为输入要运行的命令

*/

private void opencmd(String str) {

try {
Process su = Runtime.getRuntime().exec("su");//打开为root进程
String cmd = str;
cmd = cmd + "\n exit\n";//退出root进程
su.getOutputStream().write(cmd.getBytes());
if ((su.waitFor() != 0)) {
throw new SecurityException();
}
} catch (Exception e) {
System.out.println("---> 打开失败" + e.toString());
}
}
0 0
原创粉丝点击