If you're building an app blocker, a screen-time tracker or a parental-control app on Android, the first question is always the same: which app is on screen right now?
Android gives you two realistic answers: UsageStatsManager and AccessibilityService . I use both in Focsy: Doomscrolling Blocker , for different jobs. Here's how each works, what it can and can't see, and when to pick which.
Option 1: UsageStatsManager
UsageStatsManager gives you a log of app usage events: which app moved to the foreground, when, and for how long apps were used.
Permission
It needs PACKAGE_USAGE_STATS , which is a special permission.…