Is there any callback or anything (any parameter i

2020-07-27 05:37发布

I have an application requirement to announce text in a list view. The list view item gets added at run time. I have to announce them one by one. I searched on google and in android docs, but I could not reach there.

Please help me, how to know accessibility services finished reading the text?

Thanks :)

1条回答
家丑人穷心不美
2楼-- · 2020-07-27 06:15

Simple answer... don't do it this way! This is silliness. Just use the accessibility features available to you and let TalkBack (or other potential screen reader) manage it for you. Just use this utility function.

public static void announceForAccessibility(Context context, String message) {
    AccessibilityManager manager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    if (manager.isEnabled()) {

        AccessibilityEvent e = AccessibilityEvent.obtain();
        e.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        e.setClassName(context.getClass().getName());
        e.setPackageName(context.getPackageName());
        e.getText().add(message);

        manager.sendAccessibilityEvent(e);
    }
}
查看更多
登录 后发表回答