옵션 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | private void uiautomationTouch(int x, int y){ Instrumentation i = new Instrumentation(); final UiAutomation automation = i.getUiAutomation(); //UiAutomation claims to allow you to interact with other applications by leveraging the Accessibility Framework, //즉 외부 패키지 = 외부 앱 사용가능!!!!! https://www.youtube.com/watch?v=_SlBHUW0ybM //A MotionEvent is a type of InputEvent. //The event time must be the current uptime. final long eventTime = SystemClock.uptimeMillis(); //A typical click event triggered by a user click on the touchscreen creates two MotionEvents, //first one with the action KeyEvent.ACTION_DOWN and the 2nd with the action KeyEvent.ACTION_UP MotionEvent motionDown = MotionEvent.obtain(eventTime, eventTime, KeyEvent.ACTION_DOWN, x, y, 0); //We must set the source of the MotionEvent or the click doesn't work. motionDown.setSource(InputDevice.SOURCE_TOUCHSCREEN); automation.injectInputEvent(motionDown, true); MotionEvent motionUp = MotionEvent.obtain(eventTime, eventTime, KeyEvent.ACTION_UP, x, y, 0); motionUp.setSource(InputDevice.SOURCE_TOUCHSCREEN); automation.injectInputEvent(motionUp, true); //Recycle our events back to the system pool. motionUp.recycle(); motionDown.recycle(); } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | public class TestInstrumentation extends InstrumentationTestCase { @Override public void setUp() { } public void uiautomationTouch(int x, int y){ Instrumentation i = getInstrumentation(); //new Instrumentation(); final UiAutomation automation = i.getUiAutomation(); //UiAutomation claims to allow you to interact with other applications by leveraging the Accessibility Framework, //즉 외부 패키지 = 외부 앱 사용가능!!!!! https://www.youtube.com/watch?v=_SlBHUW0ybM //A MotionEvent is a type of InputEvent. //The event time must be the current uptime. final long eventTime = SystemClock.uptimeMillis(); //A typical click event triggered by a user click on the touchscreen creates two MotionEvents, //first one with the action KeyEvent.ACTION_DOWN and the 2nd with the action KeyEvent.ACTION_UP MotionEvent motionDown = MotionEvent.obtain(eventTime, eventTime, KeyEvent.ACTION_DOWN, x, y, 0); //We must set the source of the MotionEvent or the click doesn't work. motionDown.setSource(InputDevice.SOURCE_TOUCHSCREEN); automation.injectInputEvent(motionDown, true); MotionEvent motionUp = MotionEvent.obtain(eventTime, eventTime, KeyEvent.ACTION_UP, x, y, 0); motionUp.setSource(InputDevice.SOURCE_TOUCHSCREEN); automation.injectInputEvent(motionUp, true); //Recycle our events back to the system pool. motionUp.recycle(); motionDown.recycle(); } } | cs |