Write on the keyboard on android with the API


Good I am developing an application that needs to write in text boxes of another application, I would like to know how it could be written in a text box with code.

asked by EndlessLoop 01.03.2017 в 02:32

1 answer


Out of tests, you can create a MotionEvent and use dispatchTouchEvent if you know and you can access the Activity or View .

MotionEvent e = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, metaState);

The parameters are:

  • downTime: the moment in ms when the "user" touched the screen starting a flow of events
  • eventTime: the moment in ms when the event was generated
  • action: in this case MotionEvent.ACTION_DOWN, you can replace it
  • x: position x where the "user" touched
  • and: position and where the "user" touched
  • metaState: modifiers to the event (such as shift, ctrl etc.)

moments are obtained based on SystemClock.uptimeMillis() .

To get examples of these events you could do an @Override in a view or activity at dispatchTouchEvent(MotionEvent e) (do not forget to call super(e) ).

answered by 01.03.2017 в 04:36