Understand what your app is showing

Inspect the live UI hierarchy and capture screenshots to investigate layout, content, and element state in your Android app.

VisualTree tools connect what you see on screen with the elements that make up the live UI. Use hierarchy snapshots, focused node inspection, and screenshots to investigate layout or content problems.

Install

Published artifact: ai.ansight:ansight-tools-visualtree-android.

dependencies {
    debugImplementation("ai.ansight:ansight-tools-visualtree-android:latest.release")
}

Register the Suite

import ai.ansight.runtime.AnsightOptions
import ai.ansight.tools.visualtree.withVisualTreeTools

val options = AnsightOptions.createBuilder()
    .withVisualTreeTools()
    .withReadOnlyToolAccess()
    .build()

Registration API

  • withVisualTreeTools(): registers the visual tree, screenshot, and diagnostic overlay suite.
  • AndroidVisualTreeTools.create(): creates the suite tools for lower-level registration.
  • withReadOnlyToolAccess(): exposes visual tree, screenshot, node inspection, and read-only overlay tools.
  • withReadWriteToolAccess(): also exposes overlay creation, update, removal, and clearing; every overlay mutation uses Write.

Visual-Tree Providers

AndroidVisualTreeProviderRegistry always exposes the Android view hierarchy as native. Additional UI frameworks can implement AndroidVisualTreeProvider and register their own stable source:

import ai.ansight.tools.visualtree.AndroidVisualTreeProviderRegistry

AndroidVisualTreeProviderRegistry.register(
    provider = customProvider,
    replaceExisting = true,
)

The provider supplies source, displayName, getVisualTree(...), and inspectNode(...). Pass source to ui.get_visual_tree or ui.inspect_node; omitting it selects native. Responses use the shared compact visual-tree v2 contract.

Specific Concerns

  • The native provider captures every top-level Android window root owned by the foreground activity, including dialogs and popup windows when present.
  • Screenshot capture exports rendered UI content.
  • ui.get_screenshot streams bytes over the binary transfer channel.
  • Overlay removal tools use Write consistently across platforms.

Important: Calling screenshot tools will result in an FPS drop while the current frame is captured, encoded, and transferred. Avoid screenshot-heavy investigations during trend measurements unless visual evidence is required.

Tool Matrix

NameIdPolicyDescription
Get Visual Treeui.get_visual_treeReadReturns the current visual hierarchy for the requested source.
Get Screenshotui.get_screenshotReadCaptures a screenshot and streams bytes over binary transfer.
Inspect Nodeui.inspect_nodeReadReturns one node from the current visual tree.
Show Overlayui.show_overlayWriteShows a rectangular diagnostic overlay.
Get Overlayui.get_overlayReadReturns one diagnostic overlay.
Query Overlaysui.query_overlaysReadLists active diagnostic overlays.
Update Overlayui.update_overlayWriteUpdates a diagnostic overlay.
Remove Overlayui.remove_overlayWriteRemoves a diagnostic overlay.
Clear Overlaysui.clear_overlaysWriteClears diagnostic overlays.

Tool Details

Use read tools for inspection and screenshots. ui.get_visual_tree and ui.inspect_node accept an optional source argument for provider selection. Their responses include a top-level types registry referenced by each node’s typeId, semantic roles and actions, automation ids, presentation data, and structural child order. See the Visual-Tree Payload Contract. Use write tools only when the session needs to create, update, remove, or clear overlays remotely.