Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting android Activity launches

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

like image 351
Tiago Costa Avatar asked Apr 16 '13 10:04

Tiago Costa


People also ask

How does Android know which activity to run first?

Activities will very often need to support the CATEGORY_DEFAULT so that they can be found by Context. startActivity(). So, CATEGORY_DEFAULT can appear number of times. Android does not grab whichever one appears first in the manifest but it starts with activity having CATEGORY_LAUNCHER.

What is launch activity Android?

Launch mode is an instruction for Android OS which specifies how the activity should be launched. It instructs how any new activity should be associated with the current task.

How can you tell if a app is active on Android?

In Android 4.0 to 4.2, hold the "Home" button or press the "Recently Used Apps" button to view the list of running apps. To close any of the apps, swipe it to the left or to the right. In older Android versions, open the Settings menu, tap "Applications," tap "Manage Applications" and then tap the "Running" tab.


1 Answers

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

like image 100
Akhil Avatar answered Oct 03 '22 04:10

Akhil