/**
* 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();
}
Android实现全局返回(手机虚拟返回键)
最新推荐文章于 2022-11-18 11:39:12 发布