AccessibilityService在官网上的介绍如下:
An accessibility service runs in the background and receives callbacks by the system when AccessibilityEvent
s are fired. Such events denote some state transition in the user interface, for example, the focus has changed, a button has been clicked, etc. Such a service can optionally request the capability for querying the content of the active window. Development of an accessibility service requires extending this class and implementing its abstract methods.
大致的意思是它是一个运行在后台的服务,并且能够接受到系统和用户之间的交互信息,如按钮的点击,焦点变化等,它的主要功能如下:
一、获取当前UI信息
二、监听event(用户的操作)
三、响应控件
我个人觉得以上三点其实和uiautomator非常像,一和三这两点其实就是一个脚本工具的基本功能了,当然,uiautomator的会简单而且容易上手,但AccessibilityService的速度也要比uiautomator,而且功能也更全,比如用AccessibilityService去写抢红包就会比uiautomator更合适。
好了,废话不多说,这篇先说说AccessibilityService的使用。