java - Use programming to set touch input on android -


i want use programming mimic "touch" on position (x, y) on screen.

i saw this link, teaches how inject characters.

i want inject touch @ position (x, y)

how do using android sdk (which java)?

you can "fake" touch event this:

motionevent event = motionevent.obtain(downtime, eventtime, action, x, y, metastate); view.ontouchevent(event); 

api docs:

create new motionevent, filling in subset of basic motion values. not specified here are: device id (always 0), pressure , size (always 1), x , y precision (always 1), , edgeflags (always 0).

parameters:

  • downtime time (in ms) when user pressed down start stream of position events. must obtained systemclock.uptimemillis().
  • eventtime the time (in ms) when specific event generated. must obtained systemclock.uptimemillis().
  • action kind of action being performed -- 1 of either action_down, action_move, action_up, or action_cancel.
  • x x coordinate of event.
  • y y coordinate of event.
  • metastate state of meta / modifier keys in effect when event generated.

link api docs


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -