方法1:
//物理按键模拟
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
注意:不能再UI进程使用,否则报错"java.lang.RuntimeException: This method can not be called from the main application thread"
方法2:
try {
Runtime runtime = Runtime.getRuntime();
runtime.exec("input keyevent " + KeyEvent.KEYCODE_BACK);
} catch (IOException e) {
e.printStackTrace();
}
网友评论