11

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.

Problem How can I have accurate data about the apps in order to build a list of most used apps.

Base information

  • I am compiling my own Android OS (4.2 based) code so I have access to everything.
  • 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.

Some solutions

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:

  1. Use a service to query the activityManager, getRunningTasks method every X seconds and build the list ( innacurate information, also using a lot of batery ).
  2. Use the logcat to get this information (seems like a hack to me, needs system permissions)
  3. Change the activityManager itself in order to provide this information (will most likely fail the CTS tests)
  4. 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, Tiago Costa

Swati Garg
  • 995
  • 1
  • 10
  • 21
Tiago Costa
  • 971
  • 8
  • 10
  • You pretty much nailed it with listing all 4 options. My preferred one is using `(ActivityManager)this.getSystemService(ACTIVITY_SERVICE);` – srf Apr 22 '13 at 04:32
  • Thank you for the answer, I am going to try them all and see which one works best. Thanks again. – Tiago Costa Apr 23 '13 at 14:27
  • logcat does not work with Android 4.2 and later unless you have root permissions, see https://groups.google.com/forum/?fromgroups=#!topic/android-developers/6U4A5irWang – mattlaabs Apr 23 '13 at 22:16
  • Thank you for the heads up, I know that for 4.2 you have that issue, forgot to mention that in the log cat solution, will update it. – Tiago Costa Apr 24 '13 at 09:07

1 Answers1

1

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..

Akhil
  • 6,667
  • 4
  • 31
  • 61
  • Thak you for the comment, I have tried all the 4 steps and went with catching the startappplication calls in the launcher. It has almost perfect information and there is no extra processment. – Tiago Costa Jun 20 '13 at 09:31
  • Can you specify "almost perfect" ? What are you missing? – Fredrick Gauss Sep 15 '13 at 08:30
  • Applications launched within other activities that are not my launcher. Since most people launch activities via the launcher, it serves my purpose. – Tiago Costa Sep 17 '13 at 22:55
  • I am having exactly similar problem and trying to do it for quite some time now. Can you elaborate how did you catch the startapplication calls in the launcher. Some code would be appreciated. Thanks – Faheem May 09 '14 at 15:00