Skip to main content
Glama

android_uiautomator_long_click

Perform a long press on Android UI elements using resource IDs to access context menus or extended options during automated testing.

Instructions

Perform a long click on a UI element by resource ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resourceIdYesResource ID of the element to long click
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • Main handler function for android_uiautomator_long_click tool. Validates resourceId and calls ADB wrapper's longClickElementByResourceId method.
    export async function uiautomatorLongClickHandler(
      adb: ADBWrapper,
      args: any
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const { resourceId, deviceSerial } = args as UIAutomatorLongClickArgs;
    
      if (!resourceId || typeof resourceId !== 'string') {
        throw new Error('Invalid resource ID: resourceId must be a non-empty string');
      }
    
      try {
        await adb.longClickElementByResourceId(resourceId, deviceSerial);
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully long-clicked element with resource-id: ${resourceId}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`UIAutomator long click failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Core logic for long clicking: dumps UI hierarchy with uiautomator, parses bounds from XML using regex, computes center coordinates, and performs long touch using the touch method (swipe at same point for 500ms).
    async longClickElementByResourceId(resourceId: string, deviceSerial?: string): Promise<void> {
      const device = await this.getTargetDevice(deviceSerial);
      const hierarchyFile = '/sdcard/window_dump.xml';
      
      await this.exec(['shell', 'uiautomator', 'dump', hierarchyFile], device);
      const { stdout } = await this.exec(['shell', 'cat', hierarchyFile], device);
      await this.exec(['shell', 'rm', hierarchyFile], device);
      
      const boundsRegex = new RegExp(`resource-id="${resourceId}"[^>]*bounds="\\[(\\d+),(\\d+)\\]\\[(\\d+),(\\d+)\\]"`);
      const match = stdout.match(boundsRegex);
      
      if (match) {
        const x1 = parseInt(match[1], 10);
        const y1 = parseInt(match[2], 10);
        const x2 = parseInt(match[3], 10);
        const y2 = parseInt(match[4], 10);
        
        const centerX = Math.floor((x1 + x2) / 2);
        const centerY = Math.floor((y1 + y2) / 2);
        
        // Long click is typically 500ms or more
        await this.touch(centerX, centerY, 500, device);
      } else {
        throw new Error(`Element with resource-id ${resourceId} not found in UI hierarchy`);
      }
    }
  • JSON schema definition for the tool's input parameters, registered in the listTools handler.
    {
      name: 'android_uiautomator_long_click',
      description: 'Perform a long click on a UI element by resource ID',
      inputSchema: {
        type: 'object',
        properties: {
          resourceId: {
            type: 'string',
            description: 'Resource ID of the element to long click',
          },
          deviceSerial: {
            type: 'string',
            description: 'Specific device serial number to target (optional)',
          },
        },
        required: ['resourceId'],
      },
    },
  • src/index.ts:486-487 (registration)
    Registration in the tool call switch statement, dispatching to the handler function.
    case 'android_uiautomator_long_click':
      return await uiautomatorLongClickHandler(this.adb, args);
  • TypeScript type definition for handler arguments.
    interface UIAutomatorLongClickArgs {
      resourceId: string;
      deviceSerial?: string;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the action ('long click') but lacks details on behavioral traits such as duration of the long click, error handling if the element isn't found, whether it requires the app to be in the foreground, or any side effects like UI changes. This is a significant gap for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Perform a long click') and specifies the target ('UI element by resource ID'). There is no wasted verbiage, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a mutation tool with no annotations, no output schema, and incomplete behavioral disclosure, the description is inadequate. It doesn't cover key aspects like what constitutes a 'long click' (e.g., duration), error scenarios, or expected outcomes, leaving gaps that could hinder correct agent usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters (resourceId and deviceSerial). The description adds minimal value beyond the schema by implying resourceId is used for targeting the element, but it doesn't provide additional context like format examples or usage tips. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Perform a long click') on a specific resource ('UI element by resource ID'), distinguishing it from siblings like android_uiautomator_click (regular click) and android_uiautomator_double_click. It uses precise verb+resource language without being tautological.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying 'UI element by resource ID,' suggesting it's for interacting with Android UI elements identified by IDs. However, it doesn't explicitly state when to use this versus alternatives like android_touch or android_uiautomator_click, nor does it mention prerequisites like needing UI visibility or device connection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jduartedj/android-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server