Code example for Instrumentation

Methods: sendPointerSyncwaitForIdleSync

0
        long downTime = SystemClock.uptimeMillis();
        long eventTime = SystemClock.uptimeMillis();
 
        MotionEvent event = MotionEvent.obtain(downTime, eventTime,
                MotionEvent.ACTION_DOWN, x, y, 0);
        instrumentation.sendPointerSync(event);
        instrumentation.waitForIdleSync();
 
        eventTime = SystemClock.uptimeMillis();
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP,
                x, y, 0);
        instrumentation.sendPointerSync(event);
        instrumentation.waitForIdleSync();
    } 
 
    /** 
     * Sends (synchronously) a single click to the View at the specified coordinates. 
     * 
     * @param instrumentation Instrumentation object used by the test. 
     * @param v The view the coordinates are relative to. 
     * @param x Relative x location to the view.