开发者

Simulate user input

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜