a3adel a3adel - 1 month ago 53
Android Question

announceforaccessibility is not working

i'm trying to develop an application for visually impaired people, i'm using accessibility for sure
i'm trying to set a welcome for the user without the user touching anything that should be played only in accessibility mode and when the activity launches
i have a

Textview
that welcomes the user and i have set the message in the
contentDescription
of it
and
onCreate
method i call

textView.announceForAccessibility("Welcome");


i've also tried

textView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
textView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
textView.sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);


and almost every
AccessibilityEvent type
none of them works
i'm testing on nexus6p with android v7 also with accessibility enabled

Answer

Thanks to this thread earlier i ave found the answer all i did i added this snippet of code and it worked like charm

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