Lifecycle 生命周期
The lifecycle of an accessibility service is managed exclusively by
the system and follows the established service life cycle.
Additionally, starting or stopping an accessibility service is
triggered exclusively by an explicit user action through enabling
or disabling it in the device settings. After the system binds to a
service it calls
辅助服务的生命周期只被系统管理并且遵循那些已经建立的服务的生命周期的,此外,在设备的设置中,辅助服务的开始或者停止都会被用户操作所控制来启动或终结它。在系统绑定到服务它会调用onServiceConnected()方法,这个方法需要被重载
Declaration 声明
An accessibility is declared as any other service in an
AndroidManifest.xml but it must also specify that it handles the
"android.accessibilityservice.AccessibilityService" android.Manifest.permission permission
to ensure that only the system can bind to it. Failure to declare
this intent will cause the system to ignore the accessibility
service. Following is an example declaration:
. . .
辅助服务跟其他服务的声明是一样的,都需要在AndroidManifest.xml声明,但是它的声明必须是要准确的。失败的声明这个意图将会导致系统忽视辅助服务。除此之外,辅助服务必须要得到android.Manifest.permission的允许。声明方式如上:
Configuration 配置
An accessibility service can be configured to receive specific
types of accessibility events, listen only to specific packages,
get events from each type only once in a given time frame, retrieve
window content, specify a settings activity, etc.
There are two approaches for configuring an accessibility
service:
Providing ameta-dataentry
in the manifest when declaring the service. A service declaration
with a meta-data tag is presented below:
辅助服务用于接收辅助事件的特殊类型,监听特殊的包,每次从一个类型中得到一个事件,回收窗口内容,设置一个精确的活动等等,以下两种方式可以配置辅助服务。
Retrieving window content 回收窗口内容
A service can specify in its declaration that it can retrieve the
active window content which is represented as a tree of
For security purposes an accessibility service can retrieve only
the content of the currently active window. The currently active
window is defined as the window from which was fired the last event
of the following types:
The entry point for retrieving window content is through
calling AccessibilityEvent.getSource() of
the last received event of the above types or a previous event from
the same window (see AccessibilityEvent.getWindowId()).
Invoking this method will return anthat
can be used to traverse the window content which represented as a
tree of such objects.
这个服务可以精确的声明,所以它可以回收窗口内容,就像树形结构一样。标记这个声明需要通过XML参考资源服务.来声明它的配置。
Notification strategy 通知策略
For each feedback type only one accessibility service is notified.
Services are notified in the order of registration. Hence, if two
services are registered for the same feedback type in the same
package the first one wins. It is possible however, to register a
service as the default one for a given feedback type. In such a
case this service is invoked if no other service was interested in
the event. In other words, default services do not compete with
other services and are notified last regardless of the registration
order. This enables "generic" accessibility services that work
reasonably well with most applications to coexist with "polished"
ones that are targeted for specific
applications.
对于每一种反馈类型只有一个辅助辅助去通知它。被通知的服务在注册表中有序排列。因此,如果两个两个服务都被反馈成一个包的话,那么排在前面的服务会得到反馈。然而,用一个已知的反馈类型以默认的方式注册服务。在这样的例子中,这个服务会受到影响如果没有其他服务并且这个服务被最后一个通知却不管注册顺序。这使得“类”辅助服务在大多数应用程序中合理工作且共存,对于特定的应用程序像是一个“整体”。