Detecting android Activity launches

倾然丶 夕夏残阳落幕 提交于 2020-01-01 04:39:25

问题


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


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



来源:https://stackoverflow.com/questions/16034801/detecting-android-activity-launches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!