方法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();
}