As ActivityManager.getRunningTasks is deprecated from API level 21. So I decided to use UsageStatsManager instead. But getSystemService(USAGE_STATS_SERVICE) is only available from API level 22. That means I can only get the foreground package name in devices with API level >= 22 and <= 20. What about API 21 devices.
Asked
Active
Viewed 2,214 times
1 Answers
0
I am also using UsageStatsManager now to get the foreground app, and I'm running 5.0.1. Even though Android Studio says it is available from 22, it still works.
Using some code like this: https://stackoverflow.com/a/30778294/969016