Demystifying Google TalkBack: A Technical Deep Dive into Android Accessibility

Mohammad Khakpaki
Appcent
Published in
6 min readAug 31, 2023

Introduction

In the ever-evolving landscape of app development, one fundamental principle stands unwavering: inclusivity.

As technology continues to shape the way we interact with the world, it becomes imperative to ensure that everyone, regardless of their abilities, can engage seamlessly with digital experiences. This is where Android accessibility steps onto the stage, with Google TalkBack at its forefront.

As an Android developer who enjoys writing elegant code in Kotlin, you know how to create apps that engage and captivate users. The time has come for us to take that expertise a step further and embrace accessibility through the lens of Google TalkBack. This article will take you on a journey of technical exploration, delving into the mechanics and nuances of Google TalkBack, and exploring how you can leverage this powerful tool to enhance the accessibility of your Android apps.

Understanding Accessibility in Android

The importance of accessibility in Android applications extends far beyond just the visual appearance. it’s about ensuring that everyone, including users with disabilities, can interact with your app. Google’s Android Accessibility Suite provides a range of features to assist users, such as TalkBack, which functions as a screen reader. By embracing accessibility, you’re creating an environment where all users can engage with your app’s content.

Introducing Google TalkBack

Google TalkBack, now known as Android Accessibility Suite, is an accessibility service developed by Google for Android devices. It’s designed to assist individuals with visual impairments or other disabilities in using their Android devices effectively. The service provides spoken feedback and other auditory cues to help users navigate through the device’s interface, interact with apps, and access information. It’s particularly useful for those who rely on auditory or tactile feedback rather than visual cues. Android Accessibility Suite includes various features like screen reading, voice commands, and other tools to enhance the accessibility of Android devices for a diverse range of users.

The screen reading feature is designed to read aloud the content displayed on the screen while enabling users to interact and navigate through gestures. With TalkBack, your app can provide spoken feedback and help users explore your app’s UI elements.

Getting Started with Google TalkBack

Enabling TalkBack on an Android device is straightforward. Navigate to Settings > Accessibility > TalkBack, and toggle the switch. Once enabled, users can use gestures to explore your app.

For instance, you can use these gestures to navigate in your app with talkback:

  1. Single Tap: This gesture is used to select items, activate buttons, and interact with elements on the screen.
  2. Double Tap: Quickly double tapping on the screen confirms the item you’ve selected or activates the selected option.
  3. Swipe Right or Left: Swiping right or left with one finger helps you navigate through different elements on the screen, such as menus, buttons, or text.
  4. Swipe Up or Down: A vertical swipe with one finger allows you to explore content on the screen, like text and images. Swiping down can read the previous element, and swiping up reads the next one.
  5. Two-Finger Swipe Up or Down: This gesture is used to scroll through longer lists or content, like web pages or documents.
  6. Two-Finger Swipe Left or Right: This gesture lets you navigate between pages or screens, such as moving between home screens or tabs.
  7. Two-Finger Double Tap: This is a global gesture to pause or resume TalkBack speech.
  8. Three-Finger Swipe: A three-finger swipe left or right helps you navigate between pages, such as moving between tabs in a web browser.
  9. Three-Finger Swipe Up: This gesture opens the global context menu, allowing you to access various options and settings.
  10. Explore by Touch: With one finger, touch and move around the screen to explore different items. TalkBack provides spoken feedback about the item you’re currently touching.

Making Your App TalkBack-Friendly

contentDescription:
To make your app TalkBack-friendly, consider implementing content descriptions for UI elements. In Kotlin, you can set content descriptions programmatically:

view.contentDescription = "Launch the chat"

or you can set it via XML

<androidx.appcompat.widget.AppCompatImageView
android:contentDescription="Launch the chat"/>

These descriptions provide context to TalkBack users, enhancing their understanding of your app.

importantForAccessibility:
Additionally, By setting the importantForAccessibility attribute appropriately, you can control how accessibility services interact with your UI elements. This attribute is particularly useful for providing context, conveying meaningful information, and improving the overall accessibility of your app for users with disabilities.

The importantForAccessibility attribute can take the following values:

  1. auto (Default): This is the default behavior. The element’s importance for accessibility is determined by its visibility and other factors. If an element is visible on the screen, it’s generally considered important for accessibility.
  2. yes: This explicitly marks the element as important for accessibility, even if it’s not currently visible on the screen. This is useful for elements that might be off-screen but still need to be announced by accessibility services.
  3. no: This marks the element as not important for accessibility. Accessibility services will ignore this element. Use this sparingly for decorative or irrelevant elements that don’t provide any meaningful information to users.
  4. noHideDescendants: This value indicates that the element itself isn’t important for accessibility, but its child elements are. This is useful for containers or layouts where the container itself doesn’t provide meaningful information, but its children do.
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:importantForAccessibility="yes" />

accessibilityLiveRegion:
The accessibilityLiveRegion attribute is used in Android to specify how changes to a view’s content should be announced by accessibility services like TalkBack. This attribute is particularly useful when you have dynamic content updates in your app, such as changes to text or status messages, that you want to ensure are communicated clearly to users who rely on accessibility services.

The accessibilityLiveRegion attribute can take the following values:

  1. none (Default): No live region is specified. Accessibility services won’t announce changes to the view’s content automatically.

2. polite: Changes to the content in the view will be announced by accessibility services, but they will wait for a more opportune time to interrupt the ongoing speech. This is typically used for non-urgent or minor updates.

3. assertive: Changes to the content in the view will be announced immediately by accessibility services, even if it interrupts the ongoing speech. This is used for urgent or important updates that the user needs to be immediately aware of.

<TextView
android:id="@+id/statusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status: Waiting for response"
android:accessibilityLiveRegion="polite" />

Focus Management and Accessibility Tree

TalkBack relies on focus to navigate the accessibility tree. Ensure that your app’s focus management is robust and predictable. You can programmatically set focus to a specific view using:

view.requestFocus()

Also, you can use accessibilityDelegate to catch AccessibilityEvents and customize them as you want.

for example:

picker.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onRequestSendAccessibilityEvent(
host: ViewGroup?,
child: View?,
event: AccessibilityEvent?
): Boolean {
if (event?.eventType == AccessibilityEvent.TYPE_VIEW_FOCUSED || event?.eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
picker.sendAccessibilityEventUnchecked(event)
return false
}
if (event?.eventType == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
picker.sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT)
return false
}
return super.onRequestSendAccessibilityEvent(host, child, event)
}
}

This code makes the view only AccessibilityEvent.TYPE_VIEW_FOCUSED and AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED events and when text changes happen in view the accessibility engine will announce it so on this picker accessibility announces only text changes in the picker.

Finally, you can use view.announceForAccessibility("text to read") to notify the accessibility system about your announcement without user selecting any view.

Staying Updated with Accessibility Guidelines:

Accessibility guidelines evolve, so it’s crucial to stay informed. Visit the Android Developer website for the latest resources on accessibility best practices, and engage with the developer community to share insights and learn from others.

Conclusion:

In summary, this article has shown how integrating Google TalkBack into your Android apps can improve their accessibility and promote a user-centered approach to development. Armed with this knowledge, you can now create apps that cater to a wider audience, ensuring that everyone can interact with your creations.

--

--