/**
* KeyCode:KeyEvent.KEYCODE_BACK,KeyEvent.KEYCODE_HOME,KeyEvent.KEYCODE_MENU
*/
public static void sendKeyEvent(final int KeyCode) {
//必须在子线程中调用
new Thread() {
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyCode);
//这种方式也可以,但是执行速度较慢
//Runtime runtime = Runtime.getRuntime();
//runtime.exec("input keyevent " + KeyCode);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}