Why does event.getSource() return null for accessibility events that have a related source view?

女生的网名这么多〃 提交于 2019-12-25 08:50:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!