发送未链接到视图的辅助功能事件 [英] Send accessibility event not linked to view

查看:27
本文介绍了发送未链接到视图的辅助功能事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望发送未链接到视图的无障碍事件(将由 TalkBack 等接收).

We're looking to send an accessibility event (which would be picked up by TalkBack etc.) which isn't linked to a view.

例如,当 AsyncTask 完成时,我如何发送可访问性事件(例如,对讲说数据下载")?

For example, how could I send an accessibility event (e.g. talkback saying "Data downloaded") when a AsyncTask has finished?

推荐答案

如果 AccessibilityEvent.getSource() 返回 null,则 TalkBack 的当前版本似乎会忽略公告,因此您最好使用 Toast.这还有一个额外的好处,即无论用户是否使用 TalkBack,都可以向他们提供一致的反馈.

It looks like the current version of TalkBack ignores announcements if AccessibilityEvent.getSource() returns null, so you're best off using a Toast. This had the added benefit of providing consistent feedback to users whether or not they are using TalkBack.

Toast.makeText(context, /** some text */, Toast.LENGTH_SHORT).show();

不过,通常情况下,您可以手动创建一个 AccessibilityEvent 并通过 AccessibilityManager 发送它.

Normally, though, you could manually create an AccessibilityEvent and send it through the AccessibilityManager.

AccessibilityManager manager = (AccessibilityManager) context
        .getSystemService(Context.ACCESSIBILITY_SERVICE);
if (manager.isEnabled()) {
    AccessibilityEvent e = AccessibilityEvent.obtain();
    e.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
    e.setClassName(getClass().getName());
    e.setPackageName(context.getPackageName());
    e.getText().add("some text");
    manager.sendAccessibilityEvent(e);
}

这篇关于发送未链接到视图的辅助功能事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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