Simulate user input

二次信任 提交于 2019-12-11 03:32:01

问题


Is it possible to simulate user input in android ?

For example to have some service or some thread that will work in background and initiate something that will simulate user input so if we are on the home screen and simulated input(let say click) happened than the application should start if the coordinates of the simulated click point to some icon on the home screen , or let say open a clock if the simulated input points to the clock area ...

or maybe if some edittext have focus and the simulated input of keystrokes start then the edittext should be filled with some text . . .

I am sure that this can be done in .Net or java but I do not know if it is possible in android


回答1:


Is it possible to simulate user input in android ?

Only from a unit test suite. IOW, not in the way that you are thinking, as it would be a massive security hole.




回答2:


From documentation on building accesibility services:

Starting with Android 4.0 (API Level 14), accessibility services can act on behalf of users, including changing the input focus and selecting (activating) user interface elements. In Android 4.1 (API Level 16) the range of actions has been expanded to include scrolling lists and interacting with text fields. Accessibility services can also take global actions, such as navigating to the Home screen, pressing the Back button, opening the notifications screen and recent applications list.

(...)

In order to take actions on behalf of users, your accessibility service must register to receive events from a few or many applications and request permission to view the content of applications by setting the android:canRetrieveWindowContent to true in the service configuration file.

See the linked documentation for details.



来源:https://stackoverflow.com/questions/6194025/simulate-user-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!