我尝试了很多方法来获取最近和正在运行的应用程序(不是进程)的列表,但无法获取。
我查看了与此相关的所有 stackoverflow 问题,但我得到的唯一答案是关于正在运行的进程和最近的任务,而不是特定于应用程序的答案,就像我们在长按主页按钮时在三星移动任务管理器中看到的那样。
我可以通过这段代码获取正在运行的进程:
ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for(RunningAppProcessInfo runningProInfo:procInfos){
Log.d("Running Processes", "()()"+runningProInfo.processName);
}
它给出了所有进程的包名,但我只想要我已启动的应用程序的包名(最近和正在运行)。
如何从正在运行的应用程序进程中提取它?
最佳答案
更新:即使使用以下解决方案,我也看不到获取最近任务名称的方法,但这适用于当前正在运行和卡住的任务:getRunningTasks
使用 getRunningTasks
将返回 RunningTaskInfo
的列表包含基地 ComponentName
您可以通过调用 getPackageName()
来获取包名.
原始答案:
你应该看看getRecentTasks .其功能描述为
Return a list of the tasks that the user has recently launched, with the most recent being first and older ones after in order.
Note: this method is only intended for debugging and presenting task management user interfaces.
这应该会为您提供最近运行或正在运行的所有应用的列表。
关于android - 获取最近和正在运行的应用程序列表而不是进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12376646/