I want to read some instruction via accessibility as soon as My activity is launched. How can I do this? (I don't want to read out the activity label)
Asked
Active
Viewed 4,049 times
4
-
Please provvide more info...what do you want to read? a view, a string... – Benedetto Del Greco Feb 15 '17 at 11:44
-
Lets say Once I launch the activity it should say "XYZ Screen launched. Please wait while we do Blah// Blah" – Amit Feb 17 '17 at 05:48
-
Do you want this only on the first activity when you open the app or for every new activity you open? – Benedetto Del Greco Feb 17 '17 at 05:57
-
every New Activity I open. – Amit Feb 17 '17 at 06:04
1 Answers
9
You can do this by posting an accessibility announcement event.
AccessibilityManager manager = (AccessibilityManager)mService.getSystemService(Context.ACCESSIBILITY_SERVICE);
if (manager.isEnabled()) {
AccessibilityEvent e = AccessibilityEvent.obtain();
e.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
e.getText().add(message);
//There may be other things you need to add like class/packagename, I'm doing this from memory on my non-dev machine, so if this isn't quite right I apologize, I promise it's super close! :)
manager.sendAccessibilityEvent(e);
}
Note that you might not be able to do this in your activities onCreate method. There are subtle race conditions with the attachment of accessibility services. If indeed placing this in onCreate does not work, try adding it to a Runnable with a delay, or in onPostResume, which I believe is the latest callback in that chain. Ultimately though, if this is an issue, the delayed Runnable is the only reliable workaround.

MobA11y
- 18,425
- 3
- 49
- 76
-
-
It's just a generic local or class variable that represents a reference to the current Accessibility Service context. – MobA11y Oct 24 '18 at 16:49