foreground

fun foreground(instrumentation: Instrumentation, packageName: String): Boolean

Checks if the app with the given packageName is in the foreground, using the adb shell dumpsys activity activities command.

dumpsys: To dump all service info activity: To dump activity info activities: To dump all activities

Return

True if at least one activity is in foreground

Parameters

instrumentation

The instrumentation used for automated testing

packageName

The package of the app