Android应用程序中的超级用户访问权限以运行命令

时间:2014-12-13 14:18:23

标签: android root

我想要运行tap cmd超过100次,并且通过使用下面的代码,它将每次调用su并延迟点击。那么当应用程序首次启动时可以请求su然后快速运行许多命令吗?谢谢!

try {
    Process process = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(process.getOutputStream());
    String cmd = "/system/bin/input tap 350 370\n";
    os.writeBytes(cmd);
    os.writeBytes("exit\n");
    os.flush();
    os.close();
    process.waitFor();

     } catch (IOException e) {
        // TODO Auto-generated catch block

    }

1 个答案:

答案 0 :(得分:0)

这是解决方案:

try {
    Process process = Runtime.getRuntime().exec("su");
    OutputStream out = process.getOutputStream();
    String cmd = "input tap 350 370";
    out.write(cmd.getBytes());
    out.flush();
    out.close();
    process.waitFor();
} catch (IOException e) {
} catch (InterruptedException e) {
}

它对我有用