Skip to main content

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
Vision targeting solves these problems by analyzing screenshots and understanding visual context.
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)

From MainActivity.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)

From MainActivity.kt:5607-5664:

Magic Functions

magicClicker(description)

Finds and clicks UI elements using natural language:
JavaScript Usage:
Coordinate Offset: PhoneClaw adds a 50px X-offset to account for UI chrome. Adjust pixelX calculation if clicks are consistently off-target.

magicScraper(description)

Extracts text information from the screen:
JavaScript Usage:

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

Known Limitations:
  • Requires active screen capture service
  • 30-second timeout per API call
  • May struggle with very small UI elements (less than 20px)
  • Performance depends on network latency
  • Costs ~$0.01 per 100 API calls (Moondream pricing)

Best Practices

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”
❌ Bad:
  • “button” (too generic)
  • “thing” (not descriptive)
  • “icon” (too vague)
Always have a backup plan if vision fails:
Give the UI time to update between actions:

API Configuration

Authentication

Add your Moondream API key to build.gradle.kts:
In gradle.properties:

Next Steps

ClawScript API

Complete JavaScript function reference

Scheduling

Automate vision-based tasks on a schedule