Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 934
a3adel Avatar asked Oct 25 '16 14:10

a3adel


1 Answers

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);
}
like image 95
a3adel Avatar answered Oct 13 '22 01:10

a3adel