其实一开始,我是想当然的跟以前一样,开启一个全屏的透明的悬浮窗,进行遮罩的作用,但是发现,设置 Type 为 TYPE_TOAST 或者 TYPE_SYSTEM_ALERT 这样的悬浮窗某些类型的不同,会导致不单单把用户的操作屏蔽了,甚至窗口的一些状态改变也屏蔽的,导致辅助权限的 onAccessibilityEvent() 方法不回调,于是去找官方文档,查找相关悬浮窗的 Type 类型设置。然后被我找到这个属性值的 Type :
Windows that are overlaid only by a connected AccessibilityService for interception of user interactions without changing the windows an accessibility service can introspect. In particular, an accessibility service can introspect only windows that a sighted user can interact with which is they can touch these windows or can type into these windows. For example, if there is a full screen accessibility overlay that is touchable, the windows below it will be introspectable by an accessibility service even though they are covered by a touchable window.
虽然官方写的一大堆,但是我们大概能 get 到里面的意思,其实就是设置为这个类型的悬浮窗,能够使辅助功能继续响应相关窗口与内容的变化。经测试,果然设置这个类型的悬浮窗,可以一方面屏蔽用户的触摸事件,另一方继续响应自动点击的相关操作。