There are a few questions about how to receive the list of the recently used apps (either with the UsageStatsManager
or with the ActivityManager
prior to lollipop). Those all work fine and I use them successfully.
E.g. this explains how to get this list on an android lollipop and higher: How to get list of recent apps with Android API 21 Lollipop?
Problem
The problem is that the above solution (and similar ones) doesn't return the exact same list like the one which is shown when pressing the android recent apps button. Above solution also contains views like the android recent app screen itself.
Does anyone have an idea how to filter out all packages of apps that are no real apps or alternatively to get the exact same list of recent apps as the android recent apps button?
Currently, I manually filter out following packages, but there are probably more and this is not beautiful nor safe:
val systemPackages = arrayOf(
"com.android.systemui", // recent apps screen - Samsung S9 with oreo
"com.sec.android.app.launcher" // recent apps screen - Samsung S9 with pie
)