辅助服务类:AccessibilityService使用

最近又开始仔细看Android文档了。果然作为一个程序猿,还是要好好的锻炼自己的英文才行,这不但是让自己能快速读懂外国的一些文档,更是你快速学习新的技术的必备条件。有些东西只有你做了才会有所了解,只有做多了才会有所感悟,只有做多了并运用了才会熟练甚至是精通...接下来看看AccessibilityService吧。1.AccessibilityService
摘要由CSDN通过智能技术生成

最近又开始仔细看Android文档了。果然作为一个程序猿,还是要好好的锻炼自己的英文才行,这不但是让自己能快速读懂外国的一些文档,更是你快速学习新的技术的必备条件。有些东西只有你做了才会有所了解,只有做多了才会有所感悟,只有做多了并运用了才会熟练甚至是精通...


接下来看看AccessibilityService吧。


1.AccessibilityService简介


  
  
  
public abstract class AccessibilityService extends Service {...}
翻阅android开发文档可知AccessibilityService是一个继承了Service的抽象类。那么我们来读一下官方文档中对于这个类的一些定义和属性。

   
   
   
* Accessibility services are intended to assist users with disabilities in using
* Android devices and apps. They run in the background and receive callbacks by the system
* when { @link 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.

上述大概意识是:
1.这是一个为帮助残障认识使用的,可访问的辅助服务。
2.它是运作于后台,并当 AccessibilityEvents事件响应完成后,会被系统回收。
3.它可以监听设备(手机)中众多状态的改变,譬如说一个按键被点击,或是打开了一个窗口。
4.要使用它就需要创建一个类继承并实现这个类的抽象方法。

看到这里可能知道这个类除了是google提供给残障人士使用外,并无其他特别的地方。而它的运作主要是响应AccessibilityEvent事件。那么接下来我们再看看文档,看官方对AccessibilityEvent事件的解析和定义。

   
   
   
An accessibility service may have requested to be notified for
a subset of the event types, and thus be unaware when the node hierarchy has changed. It is also
possible for a node to contain outdated information because the window content may change at any
time.

上述大概意思是:
一个accessibility 服务可以监听,当设备(手机)窗体内容改变的时候,节点的层次改变也会改变,或是一个节点的信息已经过时等, 对于这些事件类型就会发出 多个不同的通知请求。

   
   
   
The event notification timeout is useful to avoid propagating
* events to the client too frequently since this is accomplished via an expensive
* interprocess call. One can think of the timeout as a criteria to determine when
* event generation has settled down

上述大概意思是:
有时候,有些事件由于用户对手机设备过于频繁的操作,导致 这些事件难以分派和传播给系统,所以google定义了一个操作这些事件的标准来规范这些事件。

看到这里大概就明白,AccessibilityEvent就是那些事件的标准,那么我们接下来看看AccessibilityEvent的定义吧:
   
   
   
<h3>Event types</h3>
* <ul>
* <li>{ @link AccessibilityEvent#TYPE_VIEW_CLICKED}</li>
* <li>{ @link AccessibilityEvent#TYPE_VIEW_LONG_CLICKED}</li>
* <li>{ @link AccessibilityEvent#TYPE_VIEW_FOCUSED}</li>
* <li>{ @link AccessibilityEvent#TYPE_VIEW_SELECTED}</li>
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值