Skip to main content
Glama

get_current_activity

Retrieve the currently displayed Android app and activity for device control and automation tasks.

Instructions

Get the currently displayed app and activity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_idNoDevice ID (optional if only one device)

Implementation Reference

  • The implementation of the `getCurrentActivity` method which queries the device using `dumpsys` and parses the result.
    async getCurrentActivity(deviceId?: string): Promise<{ packageName: string; activity: string }> {
      const output = await this.exec(["shell", "dumpsys", "activity", "activities"], deviceId);
      const patterns = [/topResumedActivity=.*?\{[^ ]* [^ ]* ([^\s/}]+)\/([^\s}]+)/, /mResumedActivity=.*?\{[^ ]* [^ ]* ([^\s/}]+)\/([^\s}]+)/];
      for (const pattern of patterns) {
        const match = output.match(pattern);
        if (match) {
          return { packageName: match[1], activity: match[2] };
        }
      }
      throw new Error("Could not determine current activity from dumpsys output");
    }
  • src/index.ts:486-498 (registration)
    Registration of the "get_current_activity" MCP tool and its handler in `src/index.ts`.
    server.tool(
      "get_current_activity",
      "Get the currently displayed app and activity",
      { device_id: z.string().optional().describe("Device ID (optional if only one device)") },
      async ({ device_id }) => {
        const info = await adb.getCurrentActivity(device_id);
        return {
          content: [
            { type: "text", text: `Package: ${info.packageName}\nActivity: ${info.activity}` },
          ],
        };
      },
    );

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/martingeidobler/android-mcp-server'

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