UiWindow
public final class UiWindow implements 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 methods |
|
|---|---|
boolean |
|
UiObject2 |
findObject(@NonNull BySelector selector)Searches all elements in the window root and returns the first one to match the |
@NonNull List<UiObject2> |
findObjects(@NonNull BySelector selector)Searches all elements under in the window root and returns those that match the |
int |
Gets the ID of the display containing this window. |
int |
getId()Returns the ID of this window. |
int |
getLayer()Returns the layer (Z-order) of the window. |
@Nullable String |
Returns the name of the package that this window belongs to. |
@Nullable UiObject2 |
Gets the root node in the window as a |
@Nullable String |
getTitle()Returns the title of the window as a String. |
int |
getType()Returns the type of the window (e.g., |
@NonNull Rect |
Returns this window's visible bounds clipped to the size of the display. |
boolean |
hasObject(@NonNull BySelector selector)Returns |
int |
hashCode() |
boolean |
isActive()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. |
@NonNull String |
toString() |
Public methods
findObject
public UiObject2 findObject(@NonNull BySelector selector)
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
public @NonNull List<UiObject2> findObjects(@NonNull BySelector selector)
Searches all elements under in the window root and returns those that match the
selector.
getDisplayId
public int getDisplayId()
Gets the ID of the display containing this window.
| Returns | |
|---|---|
int |
The current display ID, or |
| See also | |
|---|---|
getDisplayId |
getLayer
public int getLayer()
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
public @Nullable String getPackageName()
Returns the name of the package that this window belongs to.
getRootObject
public @Nullable UiObject2 getRootObject()
Gets the root node in the window as a UiObject2.
| Returns | |
|---|---|
@Nullable UiObject2 |
The root |
| See also | |
|---|---|
getRoot |
getTitle
public @Nullable String getTitle()
Returns the title of the window as a String.
| Returns | |
|---|---|
@Nullable String |
The title as a String, or null if the window has no title, or if API level <24. |
| See also | |
|---|---|
getTitle |
getType
public int getType()
Returns the type of the window (e.g., TYPE_APPLICATION).
| Returns | |
|---|---|
int |
The type. |
| See also | |
|---|---|
getType |
getVisibleBounds
public @NonNull Rect getVisibleBounds()
Returns this window's visible bounds clipped to the size of the display.
hasObject
public boolean hasObject(@NonNull BySelector selector)
Returns true if there is an element in the window which matches the selector.
isActive
public boolean isActive()
Returns if this window is active (the one the user is currently interacting with).
| Returns | |
|---|---|
boolean |
|
| See also | |
|---|---|
isActive |
isFocused
public boolean isFocused()
Returns if this window has input focus.
| Returns | |
|---|---|
boolean |
|
| See also | |
|---|---|
isFocused |
isInPictureInPictureMode
public boolean isInPictureInPictureMode()
Returns if the window is in picture-in-picture mode.
| Returns | |
|---|---|
boolean |
|
| See also | |
|---|---|
isInPictureInPictureMode |