问题
For the event TYPE_VIEW_CLICKED on android.widget.Button the event.getSource() method return null. Ideally, this event should have a source attached.
Also from Android API 18 onwards, accessibility events propagated through the sendAccessibilityEvent without a source are not sent. The documentation on which events have sources attached is missing!
Is there any other reliable way to get the AccessibilityNodeInfo of the event ? i.e Events which have related views. For Eg TYPE_WINDOW_CONTENT_CHANGED event doesnt have a view as a source
Tried on API 22 and 21
回答1:
I faced with the same problem and it is solved by setting notificationTimeout to 100. Sample code is below:
protected void onServiceConnected() {
super.onServiceConnected();
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.packageNames = new String[]{getApplicationContext().getPackageName()};
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
info.notificationTimeout = 100;
info.flags = AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
setServiceInfo(info);
}
来源:https://stackoverflow.com/questions/39833688/why-does-event-getsource-return-null-for-accessibility-events-that-have-a-rela