How to send synthesized MotionEvent through the system?

前端 未结 2 1601
悲哀的现实
悲哀的现实 2020-12-10 04:02

I know how to \"synthesize\" a MotionEvent:

  event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);

What I am

相关标签:
2条回答
  • 2020-12-10 04:32

    What you are trying to do is perfectly possible and simple:

    void simulateEventDown( View v, long x, long y )
    {
        MotionEvent e = MotionEvent.obtain( SystemClock.uptimeMillis(),
                                            SystemClock.uptimeMillis(), 
                                            MotionEvent.ACTION_DOWN, 
                                            x, y, 0);
        v.dispatchTouchEvent(e);
    }
    
    0 讨论(0)
  • 2020-12-10 04:37

    No, it's prevented by design. The concern is that such a feature can be used to subvert the entire security model - e.g. by "injecting" touches to contact the marketplace, arrange an install, accept the security warnings .. all on its own.

    This has been discussed at some length here and following.

    If this answers your question, kindly click the checkmark to the left - thanks!

    0 讨论(0)
提交回复
热议问题