通知超时 - 指定辅助功能事件之间的延迟

Jon*_*Jon 5 android

我想延迟进入我的辅助功能服务的辅助功能事件,以便辅助功能事件之间的间隔为 2 秒。这样做的目的是为了让我不会处理太多的辅助功能事件并浪费电池寿命。

通过阅读文档,正确的方法似乎是在我的服务的 xml 中指定“android:notificationTimeout”属性。

<accessibility-service
     android:accessibilityEventTypes="typeViewClicked|typeViewFocused"
     android:packageNames="com.example.android.myFirstApp, com.example.android.mySecondApp"
     android:accessibilityFeedbackType="feedbackSpoken"
     **android:notificationTimeout="2000"**
     android:settingsActivity="com.example.android.apis.accessibility.TestBackActivity"
     android:canRetrieveWindowContent="true"
/>
Run Code Online (Sandbox Code Playgroud)

然而,由于某种原因,这个通知超时似乎没有被使用。只有“第一个”可访问性事件会延迟 2 秒,但随后我将立即收到任何后续事件,不会有任何延迟。

有趣的是,我注意到文档中有一个奇怪的地方。文档中似乎有两个“notificationTimeout”条目,它们的行为明显不同。

1) https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo.html#notificationTimeout

The minimal period in milliseconds between two accessibility events of the same type are sent to this service. This setting can be changed at runtime by calling android.accessibilityservice.AccessibilityService.setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo).


2) https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo.html#attr_android:notificationTimeout

The timeout after the most recent event of a given type before an AccessibilityService is notified.
Run Code Online (Sandbox Code Playgroud)

这很令人困惑。我想使用的“notificationTimeout”的变体是第一个。但是我不确定我该怎么做。我认为我可以通过使用 XML 属性来做到这一点,就像我在示例中所使用的那样。