Overview
PhoneClaw’s Vision Targeting system uses the Moondream AI vision model to locate UI elements on screen using natural language descriptions. This enables automation scripts to interact with elements that don’t have accessible content descriptions or stable View IDs.Why Vision-Based Targeting?
Traditional Android automation relies on:- Content Descriptions: Often missing or inconsistent
- View IDs: Change between app versions
- Text Matching: Fails for icons, images, and dynamic content
- Coordinates: Break on different screen sizes
Magic Functions like
magicClicker() and magicScraper() use vision AI to interact with any visible element, regardless of its accessibility properties.Architecture
1. Screen Capture
PhoneClaw captures screenshots using Android’s MediaProjection API:2. Image Encoding
Convert bitmap to base64 for API transmission:3. Moondream API Integration
PhoneClaw uses two Moondream endpoints:Point Detection (Element Location)
FromMainActivity.kt:8498-8553:
Response Format: Moondream returns normalized coordinates (0.0-1.0) that must be scaled to device screen dimensions.
Query API (Text Extraction)
FromMainActivity.kt:5607-5664:
Magic Functions
magicClicker(description)
Finds and clicks UI elements using natural language:magicScraper(description)
Extracts text information from the screen:Data Models
MoondreamPoint
MoondreamResponse
Response Cleaning
Moondream responses are cleaned to extract concise information:Advanced Usage
Sequential Automation
Conditional Actions Based on Vision
Verification Loops
Performance Optimization
Image Compression
85% JPEG quality provides a good balance between file size (~100-200KB) and vision model accuracy.
Bitmap Memory Management
Timeout Handling
Tracking & Analytics
PhoneClaw logs all vision-based interactions for debugging:Error Handling
API Failures
No Screenshot Available
Limitations
Best Practices
Descriptive Queries
Descriptive Queries
Be specific and descriptive in your element descriptions:✅ Good:
- “red heart icon in bottom right corner”
- “blue login button at center of screen”
- “profile picture next to username”
- “button” (too generic)
- “thing” (not descriptive)
- “icon” (too vague)
Fallback Strategies
Fallback Strategies
Always have a backup plan if vision fails:
Add Delays
Add Delays
Give the UI time to update between actions:
API Configuration
Authentication
Add your Moondream API key tobuild.gradle.kts:
gradle.properties:
Next Steps
ClawScript API
Complete JavaScript function reference
Scheduling
Automate vision-based tasks on a schedule