Android 如何模拟返回键、菜单键、主页键?

如果有一个悬浮窗,运行所有程序的时候都能够看到,我希望点击悬浮窗就模拟返回键的功能,不管我现在运行的是什么程序,这个如何实现?
 
方法一:
Runtime runtime = Runtime.getRuntime();
runtime.exec("input keyevent " + KeyEvent.KEYCODE_BACK);
 
方法二:
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);

你可能感兴趣的:(Android 如何模拟返回键、菜单键、主页键?)