为什么event.getSource()对于具有相关源视图的可访问性事件返回null? [英] Why does event.getSource() return null for accessibility events that have a related source view?

查看:418
本文介绍了为什么event.getSource()对于具有相关源视图的可访问性事件返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于android.widget.TYPE中的事件TYPE_VIEW_CLICKED,请按 event.getSource()方法返回null。理想情况下,此事件应附有来源。

For the event TYPE_VIEW_CLICKED on android.widget.Button the event.getSource() method return null. Ideally, this event should have a source attached.

从Android API 18开始,可访问性事件也通过 sendAccessibilityEvent 。缺少附带事件源的文档!

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!

是否还有其他可靠的方法来获取 AccessibilityNodeInfo 事件?即具有相关视图的事件。例如, TYPE_WINDOW_CONTENT_CHANGED 事件没有将视图作为源

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

尝试使用API​​ 22和21

Tried on API 22 and 21

推荐答案

我遇到了同样的问题,可以通过将notifyTimeout设置为100来解决。示例代码如下:

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);
}

这篇关于为什么event.getSource()对于具有相关源视图的可访问性事件返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆