Make an announcement which is related to some sort of a context change. Also see
{@link android.view.View#announceForAccessibility}
// Jelly Bean added support for speaking text verbatim
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.announceForAccessibility(text);
return;
}
final Context context = view.getContext().getApplicationContext();
if (accessibilityManager == null) {
accessibilityManager = (AccessibilityManager) context.getSystemService(
Context.ACCESSIBILITY_SERVICE);
}
if (!accessibilityManager.isEnabled()) {
return;
}
final int eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
// Construct an accessibility event with the minimum recommended
// attributes. An event without a class name or package may be dropped.
final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
event.getText().add(text);
event.setEnabled(view.isEnabled());
event.setClassName(view.getClass().getName());
event.setPackageName(context.getPackageName());
// JellyBean MR1 requires a source view to set the window ID.
final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
record.setSource(view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
view.getParent().requestSendAccessibilityEvent(view, event);
} else {
// Sends the event directly through the accessibility manager.
accessibilityManager.sendAccessibilityEvent(event);
}