phonegap-plugin-mobile-accessibility
==========================================
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.
Installation
$ cordova plugin add https://github.com/phonegap/phonegap-mobile-accessibility.git
Supported Platforms
- Amazon Fire OS
- Android
- iOS
MobileAccessibility
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.
Methods
- MobileAccessibility.isScreenReaderRunning
- MobileAccessibility.isVoiceOverRunning
- MobileAccessibility.isTalkBackRunning
- MobileAccessibility.isChromeVoxActive
- MobileAccessibility.isClosedCaptioningEnabled
- MobileAccessibility.isGuidedAccessEnabled
- MobileAccessibility.isInvertColorsEnabled
- MobileAccessibility.isMonoAudioEnabled
- MobileAccessibility.isReduceMotionEnabled
- MobileAccessibility.isTouchExplorationEnabled
- MobileAccessibility.getTextZoom
- MobileAccessibility.setTextZoom
- MobileAccessibility.updateTextZoom
- MobileAccessibility.usePreferredTextZoom
- MobileAccessibility.postNotification
- MobileAccessibility.speak
- MobileAccessibility.stop
MobileAccessibility.isScreenReaderRunning(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if a screen reader is running.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while a screen reader is active. else console; } MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
- iOS
MobileAccessibility.isVoiceOverRunning(callback)
An iOS-specific proxy for the MobileAccessibility.isScreenReaderRunning
method. This method will return false
on Android and Amazon Fire OS.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while a screen reader is active. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isTalkBackRunning(callback)
An Android/Amazon Fire OS-specific proxy for the MobileAccessibility.isScreenReaderRunning
method. This method will return false
on iOS.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while a screen reader is active. else console; } MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
MobileAccessibility.isChromeVoxActive()
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.
Returns
- boolean (Boolean) Returns
true
if ChromeVox is active and properly initialized with access to the text to speech API in the WebView.
Usage
MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
MobileAccessibility.isBoldTextEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if Bold Text is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while Bold Text is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isClosedCaptioningEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if system-level closed captioning is enabled on the device.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while closed captioning is enabled. else console; } MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
- iOS
MobileAccessibility.isDarkerSystemColorsEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if Darker System Colors is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while Darker System Colors is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isGrayscaleEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if Grayscale is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while Grayscale is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isGuidedAccessEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if Guided Access is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while Guided Access is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isInvertColorsEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if the display colors have been inverted.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while Invert Colors is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isMonoAudioEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if mono audio is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application while Mono Audio is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isReduceMotionEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if reduce motion is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application when reduce motion is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isReduceTransparencyEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if reduce transparency is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application when reduce transparency is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isSpeakScreenEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if speak screen is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application when Speak Screen is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isSpeakSelectionEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if speak selection is enabled.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application when Speak Selection is enabled. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isSwitchControlRunning(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if switch control is running.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application when Switch Control is running. else console; } MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.isTouchExplorationEnabled(callback)
Makes an asynchronous call to native MobileAccessibility
to determine if Touch Exploration is enabled on Android.
Parameters
- callback (Function) A callback method to receive the boolean result asynchronously from the native
MobileAccessibility
plugin.
Usage
{ if boolean console; // Do something to improve the behavior of the application with Touch Exploration enabled. else console; // Do something to improve the behavior of the application with Touch Exploration disabled. } MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
MobileAccessibility.getTextZoom(callback)
Makes an asynchronous call to native MobileAccessibility
to return the current text zoom percent value for the WebView.
Parameters
- callback (Function) A callback method to receive the text zoom percent value asynchronously from the native
MobileAccessibility
plugin.
Usage
{ console } MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
- iOS
MobileAccessibility.setTextZoom(textZoom, callback)
Makes an asynchronous call to native MobileAccessibility
to set the current text zoom percent value for the WebView.
Parameters
- textZoom (Number) A percentage value by which text in the WebView should be scaled.
- callback (Function) A callback method to receive the new text zoom percent value asynchronously from the native
MobileAccessibility
plugin.
Usage
{ console } MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
- iOS
MobileAccessibility.updateTextZoom(callback)
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.
Parameters
- callback (Function) A callback method to receive the new text zoom percent value asynchronously from the native
MobileAccessibility
plugin.
Usage
{ console } MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
- iOS7+
MobileAccessibility.usePreferredTextZoom(boolean)
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.
Parameters
- boolean (Boolean) A Boolean value which specifies whether to use the preferred text zoom of a default percent value of 100.
Usage
MobileAccessibility; { console } MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
- iOS7+
MobileAccessibility.postNotification(mobileAccessibilityNotification, string, callback)
Posts a notification with a string for the screen reader to announce if it is running.
Parameters
- mobileAccessibilityNotification (uint) A numeric constant for the type of notification to send. Constants are defined in
MobileAccessibilityNotifications
. - string (string) A string to be announced by a screen reader.
- callback (function) A callback method to receive the asynchronous result from the native
MobileAccessibility
, when the announcement is finished, the function should expect an object containing thestringValue
that was voiced and a boolean indicating that the announcementwasSuccessful
.
Constants
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.
- MobileAccessibilityNotifications.SCREEN_CHANGED
- MobileAccessibilityNotifications.LAYOUT_CHANGED
- MobileAccessibilityNotifications.ANNOUNCEMENT
- MobileAccessibilityNotifications.PAGE_SCROLLED
MobileAccessibility;
Supported Platforms
- iOS
MobileAccessibility.speak(string, queueMode, properties)
Speaks a given string through the screenreader. On Android, if ChromeVox is active, it will use the specified queueMode and properties.
Parameters
- string (string) A string to be announced by a screen reader.
- queueMode (Optional number) Valid modes are 0 for flush; 1 for queue.
- properties (Optional Object) Speech properties to use for this utterance.
MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
- iOS
MobileAccessibility.stop()
Stops speech.
MobileAccessibility;
Supported Platforms
- Amazon Fire OS
- Android
- iOS
Events
Constants
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.
- MobileAccessibilityNotifications.BOLD_TEXT_STATUS_CHANGED
- MobileAccessibilityNotifications.CLOSED_CAPTIONING_STATUS_CHANGED
- MobileAccessibilityNotifications.DARKER_SYSTEM_COLORS_STATUS_CHANGED
- MobileAccessibilityNotifications.GRAYSCALE_STATUS_CHANGED
- MobileAccessibilityNotifications.GUIDED_ACCESS_STATUS_CHANGED
- MobileAccessibilityNotifications.INVERT_COLORS_STATUS_CHANGED
- MobileAccessibilityNotifications.MONO_AUDIO_STATUS_CHANGED
- MobileAccessibilityNotifications.REDUCE_MOTION_STATUS_CHANGED
- MobileAccessibilityNotifications.REDUCE_TRANSPARENCY_STATUS_CHANGED
- MobileAccessibilityNotifications.SCREEN_READER_STATUS_CHANGED
- MobileAccessibilityNotifications.SPEAK_SCREEN_STATUS_CHANGED
- MobileAccessibilityNotifications.SPEAK_SELECTION_STATUS_CHANGED
- MobileAccessibilityNotifications.SWITCH_CONTROL_STATUS_CHANGED
- MobileAccessibilityNotifications.TOUCH_EXPLORATION_STATUS_CHANGED
MobileAccessibilityNotifications.BOLD_TEXT_STATUS_CHANGED (boldtextstatuschanged)
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 { if info && typeof infoisBoldTextEnabled !== "undefined" if infoisBoldTextEnabled console; // Do something to improve the behavior of the application while Bold Text is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.CLOSED_CAPTIONING_STATUS_CHANGED (closedcaptioningstatuschanged)
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 { if info && typeof infoisClosedCaptioningEnabled !== "undefined" if infoisClosedCaptioningEnabled console; // Do something to improve the behavior of the application while closed captioning is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.DARKER_SYSTEM_COLORS_STATUS_CHANGED (darkersystemcolorsstatuschanged)
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 { if info && typeof infoisDarkerSystemColorsEnabled !== "undefined" if infoisDarkerSystemColorsEnabled console; // Do something to improve the behavior of the application while Darker System Colors is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.GRAYSCALE_STATUS_CHANGED (grayscalestatuschanged)
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 { if info && typeof infoisGrayscaleEnabled !== "undefined" if infoisGrayscaleEnabled console; // Do something to improve the behavior of the application while Grayscale is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.GUIDED_ACCESS_STATUS_CHANGED (guidedaccessstatuschanged)
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 { if info && typeof infoisGuidedAccessEnabled !== "undefined" if infoisGuidedAccessEnabled console; // Do something to improve the behavior of the application while Guided Access is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.INVERT_COLORS_STATUS_CHANGED (invertcolorsstatuschanged)
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 { if info && typeof infoisInvertColorsEnabled !== "undefined" if infoisInvertColorsEnabled console; // Do something to improve the behavior of the application while Invert Colors is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.MONO_AUDIO_STATUS_CHANGED (monoaudiostatuschanged)
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 { if info && typeof infoisMonoAudioEnabled !== "undefined" if infoisMonoAudioEnabled console; // Do something to improve the behavior of the application while Mono Audio is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.REDUCE_MOTION_STATUS_CHANGED (reducemotionstatuschanged)
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 { if info && typeof infoisReduceMotionEnabled !== "undefined" if infoisReduceMotionEnabled console; // Do something to improve the behavior of the application while Reduce Motion is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.REDUCE_TRANSPARENCY_STATUS_CHANGED (reducetransparencystatuschanged)
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 { if info && typeof infoisReduceTransparencyEnabled !== "undefined" if infoisReduceTransparencyEnabled console; // Do something to improve the behavior of the application while Reduce Transparency is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.SCREEN_READER_STATUS_CHANGED (screenreaderstatuschanged)
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 { if info && typeof infoisScreenReaderRunning !== "undefined" if infoisScreenReaderRunning console; // Do something to improve the behavior of the application while a screen reader is active. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.SPEAK_SCREEN_STATUS_CHANGED (speakscreenstatuschanged)
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 { if info && typeof infoisSpeakScreenEnabled !== "undefined" if infoisSpeakScreenEnabled console; // Do something to improve the behavior of the application while Speak Screen is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.SPEAK_SELECTION_STATUS_CHANGED (speakselectionstatuschanged)
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 { if info && typeof infoisSpeakSelectionEnabled !== "undefined" if infoisSpeakSelectionEnabled console; // Do something to improve the behavior of the application while Speak Selection is enabled. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.SWITCH_CONTROL_STATUS_CHANGED (switchcontrolstatuschanged)
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 { if info && typeof infoisSwitchControlRunning !== "undefined" if infoisSwitchControlRunning console; // Do something to improve the behavior of the application while Switch Control is running. else console; } // Register the callback method to handle the event window;
MobileAccessibilityNotifications.TOUCH_EXPLORATION_STATUS_CHANGED (touchexplorationstatuschanged)
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 { if info && typeof infoisTouchExplorationEnabled !== "undefined" if infoisTouchExplorationEnabled console; // Do something to improve the behavior of the application while Touch Exploration is enabled. else console; } // Register the callback method to handle the event window;