class UiWindow : Searchable


Represents a UI window on the screen and provides methods to access its properties and perform actions.

Similar to UiObject2 that wraps AccessibilityNodeInfo, a UiWindow wraps an AccessibilityWindowInfo. This represents a UI window displayed on the screen for accessibility purposes, including interactive windows like dialogs or popup windows. It is important to note that a UiWindow instance caches a snapshot of a window state. If the underlying window closes or changes and it becomes stale, UiWindow will automatically check and refresh its state internally before executing any methods.

Requires API level 24 or higher for multi-window mode.

Summary

Public functions

Boolean
equals(object: Any!)
UiObject2!

Searches all elements in the window root and returns the first one to match the selector, or null if no matching objects are found in this window.

(Mutable)List<UiObject2!>

Searches all elements under in the window root and returns those that match the selector.

Int

Gets the ID of the display containing this window.

Int

Returns the ID of this window.

Int

Returns the layer (Z-order) of the window.

String?

Returns the name of the package that this window belongs to.

UiObject2?

Gets the root node in the window as a UiObject2.

String?

Returns the title of the window as a String.

Int

Returns the type of the window (e.g., TYPE_APPLICATION).

Rect

Returns this window's visible bounds clipped to the size of the display.

Boolean
hasObject(selector: BySelector)

Returns true if there is an element in the window which matches the selector.

Int
Boolean

Returns if this window is active (the one the user is currently interacting with).

Boolean

Returns if this window has input focus.

Boolean

Returns if the window is in picture-in-picture mode.

String

Public functions

equals

fun equals(object: Any!): Boolean

findObject

fun findObject(selector: BySelector): UiObject2!

Searches all elements in the window root and returns the first one to match the selector, or null if no matching objects are found in this window.

findObjects

fun findObjects(selector: BySelector): (Mutable)List<UiObject2!>

Searches all elements under in the window root and returns those that match the selector.

getDisplayId

Added in 2.4.0-alpha06
fun getDisplayId(): Int

Gets the ID of the display containing this window.

Returns
Int

The current display ID, or DEFAULT_DISPLAY if the API level is <30.

See also
getDisplayId

getId

Added in 2.4.0-alpha06
fun getId(): Int

Returns the ID of this window.

getLayer

Added in 2.4.0-alpha06
fun getLayer(): Int

Returns the layer (Z-order) of the window. Higher layers are drawn on top of lower layers.

Returns
Int

The layer rank.

See also
getLayer

getPackageName

Added in 2.4.0-alpha06
fun getPackageName(): String?

Returns the name of the package that this window belongs to.

Returns
String?

The name of the package, or null if the root object is not available.

getRootObject

Added in 2.4.0-alpha06
fun getRootObject(): UiObject2?

Gets the root node in the window as a UiObject2.

Returns
UiObject2?

The root UiObject2, or null if the root node is not available or cannot be wrapped. The returned UiObject2 should be recycled by the caller if it holds onto the reference.

See also
getRoot

getTitle

Added in 2.4.0-alpha06
fun getTitle(): String?

Returns the title of the window as a String.

Returns
String?

The title as a String, or null if the window has no title, or if API level <24.

See also
getTitle

getType

Added in 2.4.0-alpha06
fun getType(): Int

Returns the type of the window (e.g., TYPE_APPLICATION).

Returns
Int

The type.

See also
getType

getVisibleBounds

Added in 2.4.0-alpha06
fun getVisibleBounds(): Rect

Returns this window's visible bounds clipped to the size of the display.

hasObject

fun hasObject(selector: BySelector): Boolean

Returns true if there is an element in the window which matches the selector.

hashCode

fun hashCode(): Int

isActive

Added in 2.4.0-alpha06
fun isActive(): Boolean

Returns if this window is active (the one the user is currently interacting with).

Returns
Boolean

true if the window is active.

See also
isActive

isFocused

Added in 2.4.0-alpha06
fun isFocused(): Boolean

Returns if this window has input focus.

Returns
Boolean

true if this window has input focus.

See also
isFocused

isInPictureInPictureMode

Added in 2.4.0-alpha06
fun isInPictureInPictureMode(): Boolean

Returns if the window is in picture-in-picture mode.

Returns
Boolean

true if the window is in picture-in-picture mode, false otherwise or if API level is <26.

toString

fun toString(): String