Stack Overflow archive
27 scoreaccepted

Android shell get foreground app package name

score
27
question views
24.7K
license
CC BY-SA 4.0

This worked for me:

bash
adb shell dumpsys window windows | grep -E 'mCurrentFocus' | cut -d '/' -f1 | sed 's/.* //g'

com.facebook.katana

Updated answer for Android Q as mCurrentFocus was no longer working for me:

bash
adb shell dumpsys activity recents | grep 'Recent #0' | cut -d= -f2 | sed 's| .*||' | cut -d '/' -f1

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.