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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With