1. public class RootShellCmd {
    2. private OutputStream os;
    3. /**
    4. * 执行shell指令
    5. *
    6. * @param cmd
    7. * 指令
    8. */
    9. public final void exec(String cmd) {
    10. try {
    11. if (os == null) {
    12. os = Runtime.getRuntime().exec("su").getOutputStream();
    13. }
    14. os.write(cmd.getBytes());
    15. os.flush();
    16. } catch (Exception e) {
    17. e.printStackTrace();
    18. }
    19. }
    20. /**
    21. * 后台模拟全局按键
    22. *
    23. * @param keyCode
    24. * 键值
    25. */
    26. public final void simulateKey(int keyCode) {
    27. exec("input keyevent " + keyCode + "
    28. ");
    29. }
    30. }