I'm creating a home launcher and I want to have a compatibility with the Android 5.0, Lollipop. I want to get a list of recent apps on the launcher.
But since ActivityManager.getRecentTasks()
no longer works in API 21, how can I do this ?
I'm creating a home launcher and I want to have a compatibility with the Android 5.0, Lollipop. I want to get a list of recent apps on the launcher.
But since ActivityManager.getRecentTasks()
no longer works in API 21, how can I do this ?
Using the
UsageStatsManager
, you can get the foreground package names currently running.Source: How to get recent tasks on Android "L"?
I was troubled with whis, since android has deprecated some api such as
getRecentTasks
,getRunningTasks
above API21, they say these method is no longer available to third party app. When i call these api on the device above lollipop, it just return null or my app :(.Then i found a method to instead of these api, as long as we can get the app's
packagename
, we can do almost anything we want. Android based on linux, i found this AndroidProcesses.It can use/proc
to get android's applicationpid
andprocessName
, and theprocessName
is such adcom.xxx.xxx:remote
. Notice that the front of:
is the packageName :)After get the
packageName
, i think you know what to do. I think we can start aService
to statistics the most recent used app according to the process running background. The longer the statistical time, the more accurate the results.