How to inject input events into own application on Android? -
i way how inject input events such touch or keyboard events own application, code within particular app. not android os or other apps b/c needs signature-level permission android.permission.inject_events or rooted device , have avoid both. code runs on non-rooted device without anyhow elevated rights.
i'm somehow making bit of progress code based on following concept:
view v = findviewbyid(android.r.id.content).getrootview(); v.dispatchtouchevent(e);
i think getrootview , dispatch should works well, if there problem it. please brief it.
or there more high level tricky way this. in view.java, there hide api called getviewrootimpl() return object of android.view.viewrootimpl of activity. , there method called enqueueinputevent(inputevent event) on it. can use reflection method.
as have finished project using keyboard send touch commands screen, think when trying inject these kind of events activity, multiple touch might problem. when try send finger screen. event action must action_pointer_down index shift of array named properties. , should handle properties , coordses arrays including info of fingers each time, if need move 1 finger @ time. finger's id set properties[i].id used identify finger. index of array not solid.
(int = 0; < size; i++) { properties[i].id = fingerid; properties[i].tooltype = motionevent.tool_type_finger; coordses[i].x = currentx; coordses[i].y = currenty; coordses[i].pressure = 1; coordses[i].size = default_size; } event = motionevent.obtain( mdowntime, systemclock.uptimemillis(), ((size - 1) << motionevent.action_pointer_index_shift) + motionevent.action_pointer_down, size, properties, coordses, default_meta_state, default_button_state, default_precision_x, default_precision_y, default_device_id, default_edge_flags, inputdevice.source_touchscreen, default_flags);
Comments
Post a Comment