Added in API level 4

AccessibilityManager


class AccessibilityManager
kotlin.Any
   ↳ android.view.accessibility.AccessibilityManager

System level service that serves as an event dispatch for AccessibilityEvents, and provides facilities for querying the accessibility state of the system. Accessibility events are generated when something notable happens in the user interface, for example an android.app.Activity starts, the focus or selection of a android.view.View changes etc. Parties interested in handling accessibility events implement and register an accessibility service which extends android.accessibilityservice.AccessibilityService.

Summary

Nested classes
abstract

Listener for changes to the state of accessibility services.

abstract

Listener for the system accessibility state.

abstract

Listener for the audio description by default state.

abstract

Listener for the system touch exploration state.

Constants
static Int

Use this flag to indicate the content of a UI that times out contains interactive controls.

static Int

Use this flag to indicate the content of a UI that times out contains icons.

static Int

Use this flag to indicate the content of a UI that times out contains text.

Public methods
Unit

Registers a AccessibilityRequestPreparer.

Unit

Registers a AccessibilityServicesStateChangeListener.

Unit

Registers a AccessibilityServicesStateChangeListener.

Boolean

Registers an AccessibilityStateChangeListener for changes in the global accessibility state of the system.

Unit

Registers an AccessibilityStateChangeListener for changes in the global accessibility state of the system.

Unit

Registers a AudioDescriptionRequestedChangeListener for changes in the audio description by default state of the system.

Boolean

Registers a TouchExplorationStateChangeListener for changes in the global touch exploration state of the system.

Unit

Registers an TouchExplorationStateChangeListener for changes in the global touch exploration state of the system.

Int

Gets the color of the focus rectangle.

Int

Gets the strokeWidth of the focus rectangle.

MutableList<ServiceInfo!>!

Returns the ServiceInfos of the installed accessibility services.

MutableList<AccessibilityServiceInfo!>!

Returns the AccessibilityServiceInfos of the enabled accessibility services for a given feedback type.

MutableList<AccessibilityServiceInfo!>!

Returns the AccessibilityServiceInfos of the installed accessibility services.

Int
getRecommendedTimeoutMillis(originalTimeout: Int, uiContentFlags: Int)

Get the recommended timeout for changes to the UI needed by this user.

Unit

Requests feedback interruption from all accessibility services.

static Boolean

Determines if the accessibility button within the system navigation area is supported.

Boolean

Determines if users want to select sound track with audio description by default.

Boolean

Returns if the accessibility in the system is enabled.

Boolean

Whether the current accessibility request comes from an AccessibilityService with the AccessibilityServiceInfo#isAccessibilityTool property set to true.

Boolean

Returns if the touch exploration in the system is enabled.

Unit

Unregisters a AccessibilityRequestPreparer.

Boolean

Unregisters a AccessibilityServicesStateChangeListener.

Boolean

Unregisters an AccessibilityStateChangeListener.

Boolean

Unregisters a AudioDescriptionRequestedChangeListener.

Boolean

Unregisters a TouchExplorationStateChangeListener.

Unit

Sends an AccessibilityEvent.

Constants

FLAG_CONTENT_CONTROLS

Added in API level 29
static val FLAG_CONTENT_CONTROLS: Int

Use this flag to indicate the content of a UI that times out contains interactive controls.

Value: 4

FLAG_CONTENT_ICONS

Added in API level 29
static val FLAG_CONTENT_ICONS: Int

Use this flag to indicate the content of a UI that times out contains icons.

Value: 1

FLAG_CONTENT_TEXT

Added in API level 29
static val FLAG_CONTENT_TEXT: Int

Use this flag to indicate the content of a UI that times out contains text.

Value: 2

Public methods

addAccessibilityRequestPreparer

Added in API level 27
fun addAccessibilityRequestPreparer(preparer: AccessibilityRequestPreparer!): Unit

Registers a AccessibilityRequestPreparer.

addAccessibilityServicesStateChangeListener

Added in API level 33
fun addAccessibilityServicesStateChangeListener(
    executor: Executor,
    listener: AccessibilityManager.AccessibilityServicesStateChangeListener
): Unit

Registers a AccessibilityServicesStateChangeListener.

Parameters
executor Executor: The executor. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
listener AccessibilityManager.AccessibilityServicesStateChangeListener: The listener. This value cannot be null.

addAccessibilityServicesStateChangeListener

Added in API level 33
fun addAccessibilityServicesStateChangeListener(listener: AccessibilityManager.AccessibilityServicesStateChangeListener): Unit

Registers a AccessibilityServicesStateChangeListener. This will execute a callback on the process's main handler.

Parameters
listener AccessibilityManager.AccessibilityServicesStateChangeListener: The listener. This value cannot be null.

addAccessibilityStateChangeListener

Added in API level 14
fun addAccessibilityStateChangeListener(listener: AccessibilityManager.AccessibilityStateChangeListener): Boolean

Registers an AccessibilityStateChangeListener for changes in the global accessibility state of the system. Equivalent to calling addAccessibilityStateChangeListener(android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener,android.os.Handler) with a null handler.

Parameters
listener AccessibilityManager.AccessibilityStateChangeListener: The listener. This value cannot be null.
Return
Boolean Always returns true.

addAccessibilityStateChangeListener

Added in API level 26
fun addAccessibilityStateChangeListener(
    listener: AccessibilityManager.AccessibilityStateChangeListener,
    handler: Handler?
): Unit

Registers an AccessibilityStateChangeListener for changes in the global accessibility state of the system. If the listener has already been registered, the handler used to call it back is updated.

Parameters
listener AccessibilityManager.AccessibilityStateChangeListener: The listener. This value cannot be null.
handler Handler?: The handler on which the listener should be called back, or null for a callback on the process's main handler.

addAudioDescriptionRequestedChangeListener

Added in API level 33
fun addAudioDescriptionRequestedChangeListener(
    executor: Executor,
    listener: AccessibilityManager.AudioDescriptionRequestedChangeListener
): Unit

Registers a AudioDescriptionRequestedChangeListener for changes in the audio description by default state of the system. The value could be read via isAudioDescriptionRequested.

Parameters
executor Executor: The executor on which the listener should be called back. This value cannot be null.
listener AccessibilityManager.AudioDescriptionRequestedChangeListener: The listener. This value cannot be null.

addTouchExplorationStateChangeListener

Added in API level 19
fun addTouchExplorationStateChangeListener(listener: AccessibilityManager.TouchExplorationStateChangeListener): Boolean

Registers a TouchExplorationStateChangeListener for changes in the global touch exploration state of the system. Equivalent to calling addTouchExplorationStateChangeListener(android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener,android.os.Handler) with a null handler.

Parameters
listener AccessibilityManager.TouchExplorationStateChangeListener: The listener. This value cannot be null.
Return
Boolean Always returns true.

addTouchExplorationStateChangeListener

Added in API level 26
fun addTouchExplorationStateChangeListener(
    listener: AccessibilityManager.TouchExplorationStateChangeListener,
    handler: Handler?
): Unit

Registers an TouchExplorationStateChangeListener for changes in the global touch exploration state of the system. If the listener has already been registered, the handler used to call it back is updated.

Parameters
listener AccessibilityManager.TouchExplorationStateChangeListener: The listener. This value cannot be null.
handler Handler?: The handler on which the listener should be called back, or null for a callback on the process's main handler.

getAccessibilityFocusColor

Added in API level 31
fun getAccessibilityFocusColor(): Int

Gets the color of the focus rectangle. This value can be set by AccessibilityService.

Return
Int The color of the focus rectangle.

getAccessibilityFocusStrokeWidth

Added in API level 31
fun getAccessibilityFocusStrokeWidth(): Int

Gets the strokeWidth of the focus rectangle. This value can be set by AccessibilityService.

Return
Int The strokeWidth of the focus rectangle in pixels.

getAccessibilityServiceList

Added in API level 4
Deprecated in API level 15
fun getAccessibilityServiceList(): MutableList<ServiceInfo!>!

Deprecated: Use getInstalledAccessibilityServiceList()

Returns the ServiceInfos of the installed accessibility services.

Return
MutableList<ServiceInfo!>! An unmodifiable list with ServiceInfos.

getInstalledAccessibilityServiceList

Added in API level 14
fun getInstalledAccessibilityServiceList(): MutableList<AccessibilityServiceInfo!>!

Returns the AccessibilityServiceInfos of the installed accessibility services.

Return
MutableList<AccessibilityServiceInfo!>! An unmodifiable list with AccessibilityServiceInfos.

getRecommendedTimeoutMillis

Added in API level 29
fun getRecommendedTimeoutMillis(
    originalTimeout: Int,
    uiContentFlags: Int
): Int

Get the recommended timeout for changes to the UI needed by this user. Controls should remain on the screen for at least this long to give users time to react. Some users may need extra time to review the controls, or to reach them, or to activate assistive technology to activate the controls automatically.

Use the combination of content flags to indicate contents of UI. For example, use FLAG_CONTENT_ICONS | FLAG_CONTENT_TEXT for message notification which contains icons and text, or use FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS for button dialog which contains text and button controls.

Parameters
originalTimeout Int: The timeout appropriate for users with no accessibility needs.
uiContentFlags Int: The combination of flags FLAG_CONTENT_ICONS, FLAG_CONTENT_TEXT or FLAG_CONTENT_CONTROLS to indicate the contents of UI. Value is either 0 or a combination of android.view.accessibility.AccessibilityManager#FLAG_CONTENT_ICONS, android.view.accessibility.AccessibilityManager#FLAG_CONTENT_TEXT, and android.view.accessibility.AccessibilityManager#FLAG_CONTENT_CONTROLS
Return
Int The recommended UI timeout for the current user in milliseconds.

interrupt

Added in API level 4
fun interrupt(): Unit

Requests feedback interruption from all accessibility services.

isAccessibilityButtonSupported

Added in API level 27
static fun isAccessibilityButtonSupported(): Boolean

Determines if the accessibility button within the system navigation area is supported.

Return
Boolean true if the accessibility button is supported on this device, false otherwise

isAudioDescriptionRequested

Added in API level 33
fun isAudioDescriptionRequested(): Boolean

Determines if users want to select sound track with audio description by default.

Audio description, also referred to as a video description, described video, or more precisely called a visual description, is a form of narration used to provide information surrounding key visual elements in a media work for the benefit of blind and visually impaired consumers.

The method provides the preference value to content provider apps to select the default sound track during playing a video or movie.

Add listener to detect the state change via addAudioDescriptionRequestedChangeListener

Return
Boolean true if the audio description is enabled, false otherwise.

isEnabled

Added in API level 4
fun isEnabled(): Boolean

Returns if the accessibility in the system is enabled.

Note: This query is used for sending AccessibilityEvents, since events are only needed if accessibility is on. Avoid changing UI or app behavior based on the state of accessibility. While well-intentioned, doing this creates brittle, less well-maintained code that works for some users but not others. Shared code leads to more equitable experiences and less technical debt.

For example, if you want to expose a unique interaction with your app, use ViewCompat#addAccessibilityAction in AndroidX to make this interaction - ideally with the same code path used for non-accessibility users - available to accessibility services. Services can then expose this action in the way best fit for their users.

Return
Boolean True if accessibility is enabled, false otherwise.

isRequestFromAccessibilityTool

Added in API level 34
fun isRequestFromAccessibilityTool(): Boolean

Whether the current accessibility request comes from an AccessibilityService with the AccessibilityServiceInfo#isAccessibilityTool property set to true.

You can use this method inside AccessibilityNodeProvider to decide how to populate your nodes.

Note: The return value is valid only when an AccessibilityNodeInfo request is in progress, can change from one request to another, and has no meaning when a request is not in progress.

Return
Boolean True if the current request is from a tool that sets isAccessibilityTool.

isTouchExplorationEnabled

Added in API level 14
fun isTouchExplorationEnabled(): Boolean

Returns if the touch exploration in the system is enabled.

Note: This query is used for dispatching hover events, such as android.view.MotionEvent#ACTION_HOVER_ENTER, to accessibility services to manage touch exploration. Avoid changing UI or app behavior based on the state of accessibility. While well-intentioned, doing this creates brittle, less well-maintained code that works for som users but not others. Shared code leads to more equitable experiences and less technical debt.

Return
Boolean True if touch exploration is enabled, false otherwise.

removeAccessibilityRequestPreparer

Added in API level 27
fun removeAccessibilityRequestPreparer(preparer: AccessibilityRequestPreparer!): Unit

Unregisters a AccessibilityRequestPreparer.

removeAccessibilityServicesStateChangeListener

Added in API level 33
fun removeAccessibilityServicesStateChangeListener(listener: AccessibilityManager.AccessibilityServicesStateChangeListener): Boolean

Unregisters a AccessibilityServicesStateChangeListener.

Parameters
listener AccessibilityManager.AccessibilityServicesStateChangeListener: The listener. This value cannot be null.
Return
Boolean true if the listener was previously registered.

removeAccessibilityStateChangeListener

Added in API level 14
fun removeAccessibilityStateChangeListener(listener: AccessibilityManager.AccessibilityStateChangeListener): Boolean

Unregisters an AccessibilityStateChangeListener.

Parameters
listener AccessibilityManager.AccessibilityStateChangeListener: The listener. This value cannot be null.
Return
Boolean True if the listener was previously registered.

removeAudioDescriptionRequestedChangeListener

Added in API level 33
fun removeAudioDescriptionRequestedChangeListener(listener: AccessibilityManager.AudioDescriptionRequestedChangeListener): Boolean

Unregisters a AudioDescriptionRequestedChangeListener.

Parameters
listener AccessibilityManager.AudioDescriptionRequestedChangeListener: The listener. This value cannot be null.
Return
Boolean True if listener was previously registered.

removeTouchExplorationStateChangeListener

Added in API level 19
fun removeTouchExplorationStateChangeListener(listener: AccessibilityManager.TouchExplorationStateChangeListener): Boolean

Unregisters a TouchExplorationStateChangeListener.

Parameters
listener AccessibilityManager.TouchExplorationStateChangeListener: The listener. This value cannot be null.
Return
Boolean True if listener was previously registered.

sendAccessibilityEvent

Added in API level 4
fun sendAccessibilityEvent(event: AccessibilityEvent!): Unit

Sends an AccessibilityEvent.

Parameters
event AccessibilityEvent!: The event to send.
Exceptions
java.lang.IllegalStateException if accessibility is not enabled. Note: The preferred mechanism for sending custom accessibility events is through calling android.view.ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) instead of this method to allow predecessors to augment/filter events sent by their descendants.