I have searched the stackoverflow for this question and found :
Android, Detect when other apps are launched and
Reliable way to detect application launch from home / desktop? , which kind of answers my question but it’s still not enough.
What I want to do
I want to create a widget/app that shows the user of the device a list of recent apps and a list of most used apps.
How can I have accurate data about the apps in order to build a list of most used apps.
- I am compiling my own Android OS (4.2 based) code so I have access to
- I am developing the launcher as well.
- It needs to pass the CTS and be Google approved.
- I can make the app with system privileges.
- I know that this might be a security issue for Google.
The recent apps can be found via ActityManager, getRecentApps method, so now problem there.
I have searched the web for this and already found the following solutions:
- Use a service to query the activityManager, getRunningTasks method every X seconds and build the list ( innacurate information, also using a lot of batery ).
- Use the logcat to get this information (seems like a hack to me, needs system permissions)
- Change the activityManager itself in order to provide this information (will most likely fail the CTS tests)
- Use the launcher to verify the apps that were launched (misses the apps launched inside other apps)
Anything else I have missed?
Thanks in advance,
Android default recent apps dialog implementation is best reference for you, look here..check reloadButtons()
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); final List<ActivityManager.RecentTaskInfo> recentTasks = am.getRecentTasks(MAX_RECENT_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
You can try in similar way..