[英]How to programmatically get the names of apps that currently are in the recents stack of android?
I need some code to get an object or an arraylist that contains all the names of those applications that currently are in the recents stack of android .我需要一些代码来获取一个对象或一个数组列表,其中包含当前位于 android 的最近堆栈中的那些应用程序的所有名称。 Maybe android doesn't permit to do that (for security reasons) so even code which needs root permissions is ok for me.
也许android不允许这样做(出于安全原因),所以即使是需要root权限的代码对我来说也可以。
Solution 1: 解决方案1:
Use getRunningAppProcesses
, which will return a list of RunningAppProcessInfo
objects that will give you some data about each running app. 使用
getRunningAppProcesses
,它将返回RunningAppProcessInfo
对象的列表,这些对象将为您提供有关每个正在运行的应用程序的一些数据。 One of the pieces of information you can retrieve about the app is its importance
, which can have a value IMPORTANCE_FOREGROUND
which indicates that the process is the currently active. 您可以检索到的有关该应用程序的信息之一就是它的
importance
,它可以具有值IMPORTANCE_FOREGROUND
,指示该进程当前处于活动状态。
Some guide For you as well. 一些指南也为您。
Solution 2: I was also developing an application for locking the apps. 解决方案2:我还在开发用于锁定应用程序的应用程序。 It seems you need to ask user to provide this setting.
似乎您需要要求用户提供此设置。 I used this activity to check which app is in foreground but I Guess it can work according to you also.
我使用此活动来检查哪个应用程序处于前台,但我想它也可以根据您的要求工作。
Settings.ACTION_USAGE_ACCESS_SETTINGS
On my mobile It's written 在我的手机上写道
Allow apps to monitor which other apps you use and how often,and identify your service provider, language and other usage data.
允许应用监控您使用其他哪些应用以及使用频率,并识别您的服务提供商,语言和其他使用数据。
UsageStatsManager
has some useful methods that can satisfy your need. UsageStatsManager
有一些有用的方法可以满足您的需求。
i think you need to ask this from your user and if the user agrees. 我认为您需要向您的用户询问,以及用户是否同意。 you can use gain access to the recent Apps.
您可以使用访问最新应用程序的权限。
I had a look around and your question could be answered here: 我环顾四周,您的问题可以在这里回答:
How to get App info from RecentTaskInfo? 如何从最近任务信息中获取应用信息? It's based on ActivityManager.RecentTaskInfo
它基于ActivityManager.RecentTaskInfo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.