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 obtainedsystemclock.uptimemillis()
.action
kind of action being performed -- 1 of eitheraction_down
,action_move
,action_up
, oraction_cancel
.x
x coordinate of event.y
y coordinate of event.metastate
state of meta / modifier keys in effect when event generated.
Comments
Post a Comment