==========================================
This plugin exposes information on the status of various accessibility features of mobile operating systems, including, for example, whether a screen reader is running, invert colors is enabled, and the preferred scaling for text. It also allows an application to send a string to be spoken by the screen reader, or a command to stop the screen reader from speaking.
$ cordova plugin add https://github.com/phonegap/phonegap-mobile-accessibility.git
The MobileAccessibility
object, exposed by window.MobileAccessibility
, provides methods for determining the status of accessibility features active on the user's device, methods changing the text zoom of the Cordova web view and for using the user's preferred text zoom as set in the operating system settings, and methods for sending a string to be spoken by the screen reader or to stop the screen reader from speaking.
Makes an asynchronous call to native MobileAccessibility
to determine if a screen reader is running.
MobileAccessibility
plugin. function isScreenReaderRunningCallback(boolean) {
if (boolean) {
console.log("Screen reader: ON");
// Do something to improve the behavior of the application while a screen reader is active.
} else {
console.log("Screen reader: OFF");
}
}
MobileAccessibility.isScreenReaderRunning(isScreenReaderRunningCallback);
An iOS-specific proxy for the MobileAccessibility.isScreenReaderRunning
method. This method will return false
on Android and Amazon Fire OS.
MobileAccessibility
plugin. function isVoiceOverRunningCallback(boolean) {
if (boolean) {
console.log("Screen reader: ON");
// Do something to improve the behavior of the application while a screen reader is active.
} else {
console.log("Screen reader: OFF");
}
}
MobileAccessibility.isVoiceOverRunning(isVoiceOverRunningCallback);
An Android/Amazon Fire OS-specific proxy for the MobileAccessibility.isScreenReaderRunning
method. This method will return false
on iOS.
MobileAccessibility
plugin. function isTalkBackRunningCallback(boolean) {
if (boolean) {
console.log("Screen reader: ON");
// Do something to improve the behavior of the application while a screen reader is active.
} else {
console.log("Screen reader: OFF");
}
}
MobileAccessibility.isTalkBackRunning(isTalkBackRunningCallback);
On Android, this method returns true
if ChromeVox is active and properly initialized with access to the text to speech API in the WebView.
If TalkBack is running but ChromeVox is not active, this method is useful to alert the user of a potential problem.
true
if ChromeVox is active and properly initialized with access to the text to speech API in the WebView. MobileAccessibility.isTalkBackRunning(
function (bool) {
console.log('Talkback status: ' + bool);
if (bool) {
/* Use setTimeout to account for latency in initialization of ChromeVox */
setTimeout(function() {
if (MobileAccessibility.isChromeVoxActive()) {
console.log('ChromeVox is active.');
} else {
console.log('ChromeVox is not active.');
/* Notify the user of a potential problem */
MobileAccessibility.speak('The ChromeVox screen reader has failed to initialize. You may wish to close and restart this app.');
}
}, 5000);
}
});
Makes an asynchronous call to native MobileAccessibility
to determine if Bold Text is enabled.
MobileAccessibility
plugin. function isBoldTextEnabledCallback(boolean) {
if (boolean) {
console.log("Bold Text: ON");
// Do something to improve the behavior of the application while Bold Text is enabled.
} else {
console.log("Bold Text: OFF");
}
}
MobileAccessibility.isBoldTextEnabled(isBoldTextEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if system-level closed captioning is enabled on the device.
MobileAccessibility
plugin. function isClosedCaptioningEnabledCallback(boolean) {
if (boolean) {
console.log("Closed Captioning: ON");
// Do something to improve the behavior of the application while closed captioning is enabled.
} else {
console.log("Closed Captioning: OFF");
}
}
MobileAccessibility.isClosedCaptioningEnabled(isClosedCaptioningEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if Darker System Colors is enabled.
MobileAccessibility
plugin. function isDarkerSystemColorsEnabledCallback(boolean) {
if (boolean) {
console.log("Darker System Colors: ON");
// Do something to improve the behavior of the application while Darker System Colors is enabled.
} else {
console.log("Darker System Colors: OFF");
}
}
MobileAccessibility.isDarkerSystemColorsEnabled(isDarkerSystemColorsEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if Grayscale is enabled.
MobileAccessibility
plugin. function isGrayscaleEnabledCallback(boolean) {
if (boolean) {
console.log("Grayscale: ON");
// Do something to improve the behavior of the application while Grayscale is enabled.
} else {
console.log("Grayscale: OFF");
}
}
MobileAccessibility.isGrayscaleEnabled(isGrayscaleEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if Guided Access is enabled.
MobileAccessibility
plugin. function isGuidedAccessEnabledCallback(boolean) {
if (boolean) {
console.log("Guided Access: ON");
// Do something to improve the behavior of the application while Guided Access is enabled.
} else {
console.log("Guided Access: OFF");
}
}
MobileAccessibility.isGuidedAccessEnabledEnabled(isGuidedAccessEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if the display colors have been inverted.
MobileAccessibility
plugin. function isInvertColorsEnabledCallback(boolean) {
if (boolean) {
console.log("Invert Colors: ON");
// Do something to improve the behavior of the application while Invert Colors is enabled.
} else {
console.log("Invert Colors: OFF");
}
}
MobileAccessibility.isInvertColorsEnabled(isInvertColorsEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if mono audio is enabled.
MobileAccessibility
plugin. function isMonoAudioEnabledCallback(boolean) {
if (boolean) {
console.log("Mono Audio: ON");
// Do something to improve the behavior of the application while Mono Audio is enabled.
} else {
console.log("Mono Audio: OFF");
}
}
MobileAccessibility.isMonoAudioEnabled(isMonoAudioEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if reduce motion is enabled.
MobileAccessibility
plugin. function isReduceMotionEnabledCallback(boolean) {
if (boolean) {
console.log("Reduce Motion: ON");
// Do something to improve the behavior of the application when reduce motion is enabled.
} else {
console.log("Reduce Motion: OFF");
}
}
MobileAccessibility.isReduceMotionEnabled(isReduceMotionEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if reduce transparency is enabled.
MobileAccessibility
plugin. function isReduceTransparencyEnabledCallback(boolean) {
if (boolean) {
console.log("Reduce Transparency: ON");
// Do something to improve the behavior of the application when reduce transparency is enabled.
} else {
console.log("Reduce Transparency: OFF");
}
}
MobileAccessibility.isReduceTransparencyEnabled(isReduceTransparencyEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if speak screen is enabled.
MobileAccessibility
plugin. function isSpeakScreenEnabledCallback(boolean) {
if (boolean) {
console.log("Speak Screen: ON");
// Do something to improve the behavior of the application when Speak Screen is enabled.
} else {
console.log("Speak Screen: OFF");
}
}
MobileAccessibility.isSpeakScreenEnabled(isSpeakScreenEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if speak selection is enabled.
MobileAccessibility
plugin. function isSpeakSelectionEnabledCallback(boolean) {
if (boolean) {
console.log("Speak Selection: ON");
// Do something to improve the behavior of the application when Speak Selection is enabled.
} else {
console.log("Speak Selection: OFF");
}
}
MobileAccessibility.isSpeakSelectionEnabled(isSpeakSelectionEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if switch control is running.
MobileAccessibility
plugin. function isSwitchControlRunningCallback(boolean) {
if (boolean) {
console.log("Switch Control: ON");
// Do something to improve the behavior of the application when Switch Control is running.
} else {
console.log("Switch Control: OFF");
}
}
MobileAccessibility.isSwitchControlRunning(isSwitchControlRunningCallback);
Makes an asynchronous call to native MobileAccessibility
to determine if Touch Exploration is enabled on Android.
MobileAccessibility
plugin. function isTouchExplorationEnabledCallback(boolean) {
if (boolean) {
console.log("Touch Exploration: ON");
// Do something to improve the behavior of the application with Touch Exploration enabled.
} else {
console.log("Touch Exploration: OFF");
// Do something to improve the behavior of the application with Touch Exploration disabled.
}
}
MobileAccessibility.isTouchExplorationEnabled(isTouchExplorationEnabledCallback);
Makes an asynchronous call to native MobileAccessibility
to return the current text zoom percent value for the WebView.
MobileAccessibility
plugin. function getTextZoomCallback(textZoom) {
console.log('Current text zoom = ' + textZoom + '%')
}
MobileAccessibility.getTextZoom(getTextZoomCallback);
Makes an asynchronous call to native MobileAccessibility
to set the current text zoom percent value for the WebView.
MobileAccessibility
plugin. function setTextZoomCallback(textZoom) {
console.log('WebView text should be scaled ' + textZoom + '%')
}
MobileAccessibility.setTextZoom(200, setTextZoomCallback);
Makes an asynchronous call to native MobileAccessibility
to retrieve the user's preferred text zoom from system settings and apply it to the application WebView.
MobileAccessibility
plugin. function updateTextZoomCallback(textZoom) {
console.log('WebView text should be scaled ' + textZoom + '%')
}
MobileAccessibility.updateTextZoom(callback);
Specifies whether or not the application should use the user's preferred text zoom from system settings to scale text within the WebView.
When set to true
, this method calls MobileAccessibility.updateTextZoom()
to apply new text zoom settings to the application WebView. When set to false
, the application WebView text zoom will be reset to the default value of 100
percent. The plugin uses local storage to retain the preference and will call MobileAccessibility.updateTextZoom()
after a Cordova resume
event.
MobileAccessibility.usePreferredTextZoom(true);
function getTextZoomCallback(textZoom) {
console.log('WebView text should be scaled to the preferred value ' + textZoom + '%')
}
MobileAccessibility.getTextZoom(getTextZoomCallback);
Posts a notification with a string for the screen reader to announce if it is running.
MobileAccessibilityNotifications
.MobileAccessibility
, when the announcement is finished, the function should expect an object containing the stringValue
that was voiced and a boolean indicating that the announcement wasSuccessful
.The following constants are for sending notifications to the accessibility API using the MobileAccessibility.postNotification
method. They correspond to notification constants defined in UIAccessibilityNotifications on iOS.
MobileAccessibility.postNotification(
MobileAccessibilityNotifications.ANNOUNCEMENT,
'String to be announced by screen reader.',
function(info) {
if (info) {
console.log("Screen Reader announced \"" + info.stringValue + "\" success : " + info.wasSuccessful);
}
});
Speaks a given string through the screenreader. On Android, if ChromeVox is active, it will use the specified queueMode and properties.
MobileAccessibility.speak('This string will be announced when a screen reader is active on the device.');
Stops speech.
MobileAccessibility.stop();
The following event constants are for window
events, to which an application can listen for notification of changes in the status of the accessibility features on the device.
The event fires when Bold Text has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Bold Text is active, info.isBoldTextEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onBoldTextStatusChanged(info) {
if (info && typeof info.isBoldTextEnabled !== "undefined") {
if (info.isBoldTextEnabled) {
console.log("Bold Text: ON");
// Do something to improve the behavior of the application while Bold Text is enabled.
} else {
console.log("Bold Text: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.BOLD_TEXT_STATUS_CHANGED, onBoldTextStatusChanged, false);
The event fires when system-level closed captioning on the device turns on or off.
The event returns an object, info
, with the current status of accessibility features on the device.
If closed captioning is active, info.isClosedCaptioningEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onClosedCaptioningStatusChanged(info) {
if (info && typeof info.isClosedCaptioningEnabled !== "undefined") {
if (info.isClosedCaptioningEnabled) {
console.log("Closed Captioning: ON");
// Do something to improve the behavior of the application while closed captioning is enabled.
} else {
console.log("Closed Captioning: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.CLOSED_CAPTIONING_STATUS_CHANGED, onClosedCaptioningStatusChanged, false);
The event fires when Darker System Colors has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Darker System Colors is active, info.isDarkerSystemColorsEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onDarkerSystemColorsStatusChanged(info) {
if (info && typeof info.isDarkerSystemColorsEnabled !== "undefined") {
if (info.isDarkerSystemColorsEnabled) {
console.log("Darker System Colors: ON");
// Do something to improve the behavior of the application while Darker System Colors is enabled.
} else {
console.log("Darker System Colors: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.DARKER_SYSTEM_COLORS_STATUS_CHANGED, onDarkerSystemColorsStatusChanged, false);
The event fires when Grayscale has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Grayscale is active, info.isGrayscaleEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onGrayscaleStatusChanged(info) {
if (info && typeof info.isGrayscaleEnabled !== "undefined") {
if (info.isGrayscaleEnabled) {
console.log("Grayscale: ON");
// Do something to improve the behavior of the application while Grayscale is enabled.
} else {
console.log("Grayscale: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.GRAYSCALE_STATUS_CHANGED, onGrayscaleStatusChanged, false);
The event fires when Guided Access has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Guided Access is active, info.isGuidedAccessEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onGuidedAccessStatusChanged(info) {
if (info && typeof info.isGuidedAccessEnabled !== "undefined") {
if (info.isGuidedAccessEnabled) {
console.log("Guided Access: ON");
// Do something to improve the behavior of the application while Guided Access is enabled.
} else {
console.log("Guided Access: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.GUIDED_ACCESS_STATUS_CHANGED, onGuidedAccessStatusChanged, false);
The event fires when Invert Colors has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Invert Colors is active, info.isInvertColorsEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onInvertColorsStatusChanged(info) {
if (info && typeof info.isInvertColorsEnabled !== "undefined") {
if (info.isInvertColorsEnabled) {
console.log("Invert Colors: ON");
// Do something to improve the behavior of the application while Invert Colors is enabled.
} else {
console.log("Invert Colors: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.INVERT_COLORS_STATUS_CHANGED, onInvertColorsStatusChanged, false);
The event fires when Mono Audio has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Mono Audio is active, info.isMonoAudioEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onMonoAudioStatusChanged(info) {
if (info && typeof info.isMonoAudioEnabled !== "undefined") {
if (info.isMonoAudioEnabled) {
console.log("Mono Audio: ON");
// Do something to improve the behavior of the application while Mono Audio is enabled.
} else {
console.log("Mono Audio: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.MONO_AUDIO_STATUS_CHANGED, onMonoAudioStatusChanged, false);
The event fires when Reduce Motion has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Reduce Motion is active, info.isReduceMotionEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onReduceMotionStatusChanged(info) {
if (info && typeof info.isReduceMotionEnabled !== "undefined") {
if (info.isReduceMotionEnabled) {
console.log("Reduce Motion: ON");
// Do something to improve the behavior of the application while Reduce Motion is enabled.
} else {
console.log("Reduce Motion: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.REDUCE_MOTION_STATUS_CHANGED, onMReduceMotionStatusChanged, false);
The event fires when Reduce Transparency has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Reduce Transparency is active, info.isReduceTransparencyEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onReduceTransparencyStatusChanged(info) {
if (info && typeof info.isReduceTransparencyEnabled !== "undefined") {
if (info.isReduceTransparencyEnabled) {
console.log("Reduce Transparency: ON");
// Do something to improve the behavior of the application while Reduce Transparency is enabled.
} else {
console.log("Reduce Transparency: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.REDUCE_TRANSPARENCY_STATUS_CHANGED, onReduceTransparencyStatusChanged, false);
The event fires when a screen reader on the device turns on or off.
The event returns an object, info
, with the current status of accessibility features on the device.
If a screen reader is active, info.isScreenReaderRunning
will equal true
.
// Define a persistent callback method to handle the event
function onScreenReaderStatusChanged(info) {
if (info && typeof info.isScreenReaderRunning !== "undefined") {
if (info.isScreenReaderRunning) {
console.log("Screen reader: ON");
// Do something to improve the behavior of the application while a screen reader is active.
} else {
console.log("Screen reader: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.SCREEN_READER_STATUS_CHANGED, onScreenReaderStatusChanged, false);
The event fires when Speak Screen has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Speak Screen is active, info.isSpeakScreenEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onSpeakScreenStatusChanged(info) {
if (info && typeof info.isSpeakScreenEnabled !== "undefined") {
if (info.isSpeakScreenEnabled) {
console.log("Speak Screen: ON");
// Do something to improve the behavior of the application while Speak Screen is enabled.
} else {
console.log("Speak Screen: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.SPEAK_SCREEN_STATUS_CHANGED, onSpeakScreenStatusChanged, false);
The event fires when Speak Selection has been enabled on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Speak Selection is active, info.isSpeakSelectionEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onSpeakSelectionStatusChanged(info) {
if (info && typeof info.isSpeakSelectionEnabled !== "undefined") {
if (info.isSpeakSelectionEnabled) {
console.log("Speak Selection: ON");
// Do something to improve the behavior of the application while Speak Selection is enabled.
} else {
console.log("Speak Selection: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.SPEAK_SELECTION_STATUS_CHANGED, onSpeakSelectionStatusChanged, false);
The event fires when Switch Control is running on an iOS device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Switch Control is running, info.isSwitchControlRunning
will equal true
.
// Define a persistent callback method to handle the event
function onSwitchControlStatusChanged(info) {
if (info && typeof info.isSwitchControlRunning !== "undefined") {
if (info.isSwitchControlRunning) {
console.log("Switch Control: ON");
// Do something to improve the behavior of the application while Switch Control is running.
} else {
console.log("Switch Control: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.SWITCH_CONTROL_STATUS_CHANGED, onSwitchControlStatusChanged, false);
The event fires when Touch Exploration has been enabled on an Android device.
The event returns an object, info
, with the current status of accessibility features on the device.
If Touch Exploration is active, info.isTouchExplorationEnabled
will equal true
.
// Define a persistent callback method to handle the event
function onTouchExplorationChanged(info) {
if (info && typeof info.isTouchExplorationEnabled !== "undefined") {
if (info.isTouchExplorationEnabled) {
console.log("Touch Exploration: ON");
// Do something to improve the behavior of the application while Touch Exploration is enabled.
} else {
console.log("Touch Exploration: OFF");
}
}
}
// Register the callback method to handle the event
window.addEventListener(MobileAccessibilityNotifications.TOUCH_EXPLORATION_STATUS_CHANGED, onTouchExplorationChanged, false);