我想知道是否可以模拟双敲事件。我试过
TouchUtils.clickView(...)
连续两次,但它没有工作。我也尝试过这种方式:
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
eventTime +=200;
downTime +=200;
Instrumentation instrumentation = getInstrumentation();
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, mainview.getWidth()/2, mainview.getHeight()/2, 0);
instrumentation.sendPointerSync(event);
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, mainview.getWidth()/2, mainview.getHeight()/2, 0);
instrumentation.sendPointerSync(event);
downTime = SystemClock.uptimeMillis();
eventTime = SystemClock.uptimeMillis();
eventTime +=200;
downTime += 200;
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, mainview.getWidth()/2, mainview.getHeight()/2, 0);
instrumentation.sendPointerSync(event);
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, mainview.getWidth()/2, mainview.getHeight()/2, 0);
instrumentation.sendPointerSync(event);
但事件仍然没有触发。