替代Android中大号getRunningTasks大号、Android、getRunningTasks

2023-09-12 22:32:28 作者:(~)と媼яδμ╰☆╮

它已经有据可查的getRunningTasks现在是很precated在Android中L.我用这个来获得最高的活动,这是我的应用程序的一个重要特征。虽然没有完整的,在Android中L的新的解决方案已承诺由谷歌员工。该解决方案规定:

It's been well documented that getRunningTasks is now deprecated in Android L. I used this to get top activity and this was an important feature of my app. Though not complete, a new solution in Android L has been promised by a Google Employee. The solution states:

对于L我们计划有一个新的解决方案,将解决一些getRecentTasks()的现有用例:我们希望能够揭露系统内部使用统计信息服务的一个新的扩展形式是可用的为第三方应用通过SDK。的

新的使用情况统计信息服务,应该有两个信息主要部分。首先,它将提供的时间,用户在每个应用程序花费,以及这些应用程序的最后发射时间汇总统计,卷起在数天,数周,月和年。其次,它将包括在过去的几天里详细的使用事件,描述的时间和组件名时,任何过渡到前台或后台。的

访问到这个新的使用情况数据会要求用户明确授予通过新设置的用户界面的应用程序访问使用状态。他们将能够看到可以访问所有应用程序,并撤销在任何时候访问。的

我知道这不会涵盖所有可能使用旧getRecentsTask API,我为此道歉。然而,我们看到的是API的关键目前的使用,一个新的使用统计数据的API应该是更加强大和高效。的

您可以阅读更多关于它在这里:https://$c$c.google.com/p/android-developer-$p$pview/issues/detail?id=29#c50

You can read more about it here: https://code.google.com/p/android-developer-preview/issues/detail?id=29#c50

我试图寻找了Android l文献资料中却找不到任何东西,讨论上面提到的使用统计信息服务。有没有人使用这个API?任何人都可以点我这方面的文档?

I have tried looking in the Android L documentation but cannot find anything that talks the usage stats service mentioned above. Has anyone used this API? Can anyone point me to the documentation for this?

推荐答案

系统统计你的问题的API诱发也是presented的此处和详细的API是的此处。据我可以看到这个API不会让你得到了目前顶级的活动。

The system statistics api evoked in your question is also presented here and the detailed API is here. As far as I can see this API won't allow you to get the current top activity.

即。你必须接受 UsageEvent 同类型 MOVE_TO_FOREGROUND 通过使用 UsageStatsManager.queryEvents 但据 javadoc中:

i.e. you have the ability to receive UsageEvent with the type MOVE_TO_FOREGROUND by using UsageStatsManager.queryEvents but according javadoc :

事件日志的最后几分钟将被截断,以prevent虐待的应用程序。

The last few minutes of the event log will be truncated to prevent abuse by applications.

所以这是一个真正的API来获取统计数据,无法得到实时信息。 (请注意,现在去precated getRunningTasks()既不是为了获取实时数据:的javadoc )

So it is really an API to get statistics, not to get realtime information. (note that the now deprecated getRunningTasks() was neither intended to retrieve realtime data : javadoc)

在另一方面,如果你只关心的您自己的应用程序热门活动:你可以使用的 getAppTasks() 返回的 名单,其中,AppTask> 在那里你可以得到的 RecentTaskInfo 与 getTaskInfo

On the other hand, if you are only interested in top activity of your own app: you can use getAppTasks() returning a List<AppTask> where you can get the RecentTaskInfo with getTaskInfo

编辑:提供另一种方法here.

EDIT : another approach is provided here.

它基于 UsageStats 和的 UsageStats.getLastTimeUsed()。缺点:需要额外的许可,只能为您提供软件包名称 - 不是的活动 - ,但它可以让你实时数据。

It is based on UsageStats and UsageStats.getLastTimeUsed(). Drawback : it requires additional permission and gives you only the package name -not the activity-, but it gives you real time data.