问题
I'd like to delay the accessibility events coming into my accessibility service so that the gap between accessibility events is 2 seconds. This is intended so that I do not process too many accessibility events and waste battery life.
From reading the documentation, the proper way seems to be specifying the "android:notificationTimeout" attribute in my xml for my service.
<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"
/>
However, for some reason, this notification timeout doesn't seem to be getting used. Only the "first" accessibility event will be delayed by the 2 seconds but then I will receive any subsequent event immediately after without any delay.
Interestingly enough, I noticed an oddity in the documentation. There seems to be two "notificationTimeout" entries in the documentation and they have clearly different behavior.
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.
This is confusing. The variant of the "notificationTimeout" I'd like to use is the first one. However I am not sure how I do this. I thought I can do this by using the XML attribute as I have in my example.
来源:https://stackoverflow.com/questions/49743949/notification-timeout-specifying-delay-between-accessibility-events