I always thought of accessibility services in Android meant to help people with visual or physical disabilities in accessing apps, until recently, when I came across few apps which requests user to turn on their custom accessibility service in order to work properly. To my surprise, these apps are in no way related to aiding accessibility for visual or physical impaired people. So I started looking into details of accessibility service. I will be sharing my findings in a series of two blogs.

This post explains what accessibility service is and how can we make our apps accessible. Next post will talk about creating custom accessibility services.

What are Accessibility services?

Accessibility services are a feature of Android framework designed to provide alternative navigation feedback to the user. These services run in the background and receive callbacks from the system when AccessibilityEvents are fired. These events are sent by the system when something notable happens in the user interface, for example, the focus has changed, a button has been clicked, etc.

We, as developers should make our apps accessible to all, for greater reachability. Below are a few strategies which would assist us in making accessible applications:

1. Adding content descriptions

contentDescriptions are labels given to UI elements which will be read out loud when user enables accessibility service like TalkBack.

One can add it in xml

or programmatically

paymentButton.setContentDescription(“Make Payment”);

2. Enable focus navigation

Most of the apps have touchscreen as the only available mode of navigation but by enabling focus navigation in our apps we can let users use D-pad (Directional Pad) or external devices like keyboards or mouse to navigate through the app.
To implement this, one should set android:focusable attribute for every UI control to true and to enable user to navigate using direction keys, one should provide
android:nextFocusUp, android:nextFocusDown, android:nextFocusLeft and android:nextFocusRight. Now, when user is on an element and uses direction key, respective element will be focused.

For example, let us consider a view having four buttons as shown in the screenshot below. To enable user to navigate among these buttons using D-Pad or external controllers we have to add nextFocus element for each direction.
Here is the gist of code :
Corresponding style xml:

The demo application for this example can be found here.

3. Fire accessibility events from custom views:

Android framework fires AccessibilityEvents whenever there is a change of focus in UI elements. Depending on the specifics of our custom views, we should also fire respective AccessibilityEvents to make our app completely accessible.

For example, here is a custom view which comprises of an ImageView and two TextViews.

When ImageView is clicked the current location of the device is accessed and address of that location obtained by reverse geocoding is displayed on one of the TextViews. The other TextView is used to display a static text.


To make this component accessible, AccessibilityEvent should be sent like this:

This was all about making our apps accessible. In next post I will explain about making custom accessibility services.

Stay tuned!

Share this: