button 的onclick方法中使用如下:
InputManager iMgr = (InputManager) mContext.getSystemService(mContext.INPUT_SERVICE);
if (iMgr != null) {
long time = SystemClock.uptimeMillis();
KeyEvent evt = new KeyEvent(time, time,
true ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_BACK, 0);
iMgr.injectInputEvent(evt, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
evt = new KeyEvent(time, time,
false ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_BACK, 0);
iMgr.injectInputEvent(evt, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
}
即可。