public abstract class

AccessibilityService

extends Service
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.accessibilityservice.AccessibilityService

Class Overview

An accessibility service runs in the background and receives callbacks by the system when AccessibilityEvents are fired. Such events denote some state transition in the user interface, for example, the focus has changed, a button has been clicked, etc.

An accessibility service extends this class and implements its abstract methods. Such a service is declared as any other service in an AndroidManifest.xml but it must also specify that it handles the "android.accessibilityservice.AccessibilityService" Intent. Following is an example of such a declaration:

<service android:name=".MyAccessibilityService">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>

The lifecycle of an accessibility service is managed exclusively by the system. Starting or stopping an accessibility service is triggered by an explicit user action through enabling or disabling it in the device settings. After the system binds to a service it calls onServiceConnected(). This method can be overriden by clients that want to perform post binding setup. An accessibility service is configured though setting an AccessibilityServiceInfo by calling setServiceInfo(AccessibilityServiceInfo). You can call this method any time to change the service configuration but it is good practice to do that in the overriden onServiceConnected().

An accessibility service can be registered for events in specific packages to provide a specific type of feedback and is notified with a certain timeout after the last event of interest has been fired.

Notification strategy

For each feedback type only one accessibility service is notified. Services are notified in the order of registration. Hence, if two services are registered for the same feedback type in the same package the first one wins. It is possible however, to register a service as the default one for a given feedback type. In such a case this service is invoked if no other service was interested in the event. In other words, default services do not compete with other services and are notified last regardless of the registration order. This enables "generic" accessibility services that work reasonably well with most applications to coexist with "polished" ones that are targeted for specific applications.

Event types

TYPE_VIEW_CLICKED TYPE_VIEW_LONG_CLICKED TYPE_VIEW_FOCUSED TYPE_VIEW_SELECTED TYPE_VIEW_TEXT_CHANGED TYPE_WINDOW_STATE_CHANGED TYPE_NOTIFICATION_STATE_CHANGED

Feedback types

FEEDBACK_AUDIBLE FEEDBACK_HAPTIC FEEDBACK_AUDIBLE FEEDBACK_VISUAL FEEDBACK_GENERIC

Summary

Constants
String SERVICE_INTERFACE The Intent that must be declared as handled by the service.
[Expand]
Inherited Constants
From class android.app.Service
From class android.content.Context
Public Constructors
AccessibilityService()
Public Methods
abstract void onAccessibilityEvent(AccessibilityEvent event)
Callback for AccessibilityEvents.
final IBinder onBind(Intent intent)
Implement to return the implementation of the internal accessibility service interface.
abstract void onInterrupt()
Callback for interrupting the accessibility feedback.
final void setServiceInfo(AccessibilityServiceInfo info)
Sets the AccessibilityServiceInfo that describes this service.
Protected Methods
void onServiceConnected()
This method is a part of the AccessibilityService lifecycle and is called after the system has successfully bound to the service.
[Expand]
Inherited Methods
From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks

Constants

public static final String SERVICE_INTERFACE

Since: API Level 4

The Intent that must be declared as handled by the service.

Constant Value: "android.accessibilityservice.AccessibilityService"

Public Constructors

public AccessibilityService ()

Since: API Level 4

Public Methods

public abstract void onAccessibilityEvent (AccessibilityEvent event)

Since: API Level 4

Callback for AccessibilityEvents.

Parameters
event An event.

public final IBinder onBind (Intent intent)

Since: API Level 4

Implement to return the implementation of the internal accessibility service interface. Subclasses should not override.

Parameters
intent The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.
Returns
  • Return an IBinder through which clients can call on to the service.

public abstract void onInterrupt ()

Since: API Level 4

Callback for interrupting the accessibility feedback.

public final void setServiceInfo (AccessibilityServiceInfo info)

Since: API Level 4

Sets the AccessibilityServiceInfo that describes this service.

Note: You can call this method any time but the info will be picked up after the system has bound to this service and when this method is called thereafter.

Parameters
info The info.

Protected Methods

protected void onServiceConnected ()

Since: API Level 4

This method is a part of the AccessibilityService lifecycle and is called after the system has successfully bound to the service. If is convenient to use this method for setting the AccessibilityServiceInfo.