现在的位置: 首页 > 综合 > 正文

Android 模拟返回键功能

2013年09月16日 ⁄ 综合 ⁄ 共 257字 ⁄ 字号 评论关闭

我测试发现,有两种方法可行。
①、java.lang.Runtime

  1. Runtime runtime = Runtime.getRuntime();
  2. runtime.exec("input keyevent " + KeyEvent.KEYCODE_BACK);

②、android.app.Instrumentation

  1. Instrumentation inst = new Instrumentation();
  2. inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);

都测试成功了。可以实现 按BACK 的效果。

抱歉!评论已关闭.