Code example for AccessibilityManager

Methods: isEnabled, sendAccessibilityEvent

0
     * spoken. 
     * 
     * @param text the text to speak 
     */ 
    public void speak(CharSequence text) {
        if (!mAccessibilityManager.isEnabled()) {
            Log.e(TAG, "Attempted to speak when accessibility was disabled!");
            return; 
        } 
 
        // The following is a hack to avoid using the heavy-weight TextToSpeech 
        // class. Instead, we're just forcing a fake AccessibilityEvent into 
        // the screen reader to make it speak. 
        final AccessibilityEvent event = AccessibilityEvent
                .obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
 
        event.setPackageName(PACKAGE);
        event.setClassName(CLASS);
        event.setEventTime(SystemClock.uptimeMillis());
        event.setEnabled(true);
        event.getText().add(text);
 
        mAccessibilityManager.sendAccessibilityEvent(event);
    } 
 
    /** 
     * Handles speaking the "connect a headset to hear passwords" notification 
     * when connecting to a password field.