首先,要确保你手机是已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());
}
}
版权声明:本文为Lou__chen原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。