Android 模拟返回键功能

我测试发现,有两种方法可行。
①、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 的效果。

你可能感兴趣的:(android,返回键)