发送未链接到浏览辅助活动 [英] Send accessibility event not linked to view
问题描述
我们正在寻找发送访问事件(这将拾起话语提示等)未链接到一个视图。
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,所以你最好使用吐司。这有提供一致的反馈给用户是否他们正在使用话语提示的附加好处。
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屋!