Introduction
TheMyAccessibilityService class provides low-level Android automation capabilities through the Android Accessibility Service API. This service allows PhoneClaw to interact with UI elements, simulate gestures, and extract screen content without requiring root access.
Service Lifecycle
The Accessibility Service maintains a singleton instance that is automatically managed by the Android system.Service Connection
Lifecycle Methods
Called when the accessibility service is successfully connected. Sets the singleton instance.
Called when the service is destroyed. Clears the singleton instance.
Called when the accessibility service is interrupted.
Handles accessibility events from the system. Currently unused but available for event monitoring.
Core Capabilities
The Accessibility Service provides three main categories of functionality:1. Node Operations
Find and interact with UI elements using various search strategies:- By Content Description:
clickByDesc(description) - By View ID:
clickElementByViewId(viewId) - By Text Label:
clickButtonWithLabel(label) - By Class and Index:
findNodeByClassNameAndIndexAndString()
2. Gestures
Simulate touch gestures and user interactions:- Tap:
simulateClick(x, y) - Swipe:
simulateSwipe(startX, startY, endX, endY) - Scroll:
simulateScrollToBottom(),simulateScrollToTop()
3. Text Operations
Type text into input fields and extract screen content:- Type Text:
simulateTypeInFirstEditableField(text) - Extract Content:
getAllTextFromScreen() - Press Enter:
pressEnterKey()
Requirements
API Level Requirements
Some methods require specific Android API levels:- Gesture simulation (tap, swipe): API 24 (Android 7.0) or higher
- View ID lookup: API 18 (Android 4.3) or higher
- IME Enter action: API 33 (Android 13) or higher (with fallback for older versions)
Usage Example
Error Handling
All methods handle errors gracefully and log detailed information:Best Practices
Always check if the service instance is available before calling methods
Use descriptive search terms that are unlikely to change between app versions
Add delays between actions to allow the UI to update
Verify actions succeeded by checking for expected UI changes
Debugging
The service logs detailed information to help debug automation issues:"Accessibility Service Connected"- Service started successfully"rootInActiveWindow is null"- No active window (app may be in background)"No node with text found"- Element search failed"Clicked center of bounds"- Gesture fallback was used
Next Steps
Node Operations
Learn how to find and click UI elements
Gestures
Simulate taps, swipes, and scrolls