Accessibility Dialogs
๐ง What Is the Accessibility Dialog and Custom Accessibility Service?
๐ 1. Purpose
In the app ZMantra
, the goal is to assist users with visual impairments or those who rely on screen readers (like TalkBack). To support this, the app:
- Uses a custom accessibility service (
MathsManthraAccessibilityService
) to monitor user focus and interactions. - Prompts users with an Accessibility Dialog if they havenโt enabled required accessibility settings.
๐ 2. Accessibility Dialog: What It Is and Why Itโs Shown
โ What It Does
This dialog appears when either:
- TalkBack is ON but
- Your custom service (
MathsManthraAccessibilityService
) is NOT enabled
It informs the user that they need to enable the custom service and redirects them to the Accessibility Settings screen.
โ๏ธ How It Works (Code Path)
- Triggered inside
MainActivity
:
if (!isServiceEnabled || !isTalkBackEnabled) {
Handler(Looper.getMainLooper()).postDelayed({
AccessibilityHelper.enforceAccessibilityRequirement(this)
}, 500)
}
- Then calls:
AccessibilityHelper.enforceAccessibilityRequirement(context)
Which checks:
if (!isServiceEnabled && isTalkBackOn) {
showAccessibilityDialog(context)
}
- And finally shows this dialog:
AlertDialog.Builder(context)
.setTitle("Enable Accessibility")
.setMessage("Please enable MathsManthra Accessibility Service in settings.")
.setPositiveButton("Enable") {
context.startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
}
โฟ 3. Custom Accessibility Service: MathsManthraAccessibilityService
๐ What It Does
This service listens for specific accessibility events like:
TYPE_VIEW_ACCESSIBILITY_FOCUSED
: when a user focuses on a view via screen readerTYPE_WINDOW_STATE_CHANGED
: when the app's window changes
It logs these events and updates internal app state, like:
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
service.updateWindowState();
}
This lets your app respond only when your app is in focus (checked via package name) and adapt the UI or hints as needed.
โ๏ธ How Itโs Registered
This is declared in your AndroidManifest.xml
(not shown here but assumed), and needs to be manually enabled by the user in Settings > Accessibility.
Once enabled, it stays active in the background while your app is open.
๐ 4. AccessibilityHelper: Glue Between UI & Service
This class handles:
- Checking if your service is enabled
- Opening settings
- Disabling/enabling touch passthrough regions (for advanced UI focus)
- Holding a reference to the running service instance
๐งช Developer Summary
Feature | Purpose | Location in Code |
---|---|---|
Accessibility Dialog | Prompts users to enable the custom service | AccessibilityHelper.showAccessibilityDialog() |
Custom Accessibility Service | Monitors screen reader focus and interaction events | MathsManthraAccessibilityService.kt/java |
System TalkBack Detection | Ensures TalkBack is enabled | AccessibilityUtils.isSystemExploreByTouchEnabled() |
Service Enable Check | Confirms your service is active | AccessibilityHelper.isMathsManthraAccessibilityServiceEnabled() |