为什么我无法以编程方式在Android中看到所有正在运行的应用程序? [英] Why i can't see all Running Apps in Android Programmatically?

查看:59
本文介绍了为什么我无法以编程方式在Android中看到所有正在运行的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试列出所有正在运行的应用程序,但是我不知道为什么我不能这样做.

I'm trying to list all running Apps but i don't know why i can't do it.

当我尝试运行以下命令时,我只返回了我的应用程序.

When i try to run the following command, i just have mine application returned.

List<ActivityManager.RunningAppProcessInfo> listProcesses = manager.getRunningAppProcesses();

许多网站都告诉您使用

List<ActivityManager.RunningTaskInfo> alltasks = am.getRunningTasks(Integer.MAX_VALUE);

而且还刚刚退回了我的申请

But also just returned my application

没有root权限可以使所有任务/进程运行吗?

Is there anything to do without root to get all task/process running ?

推荐答案

如上所述,从Android 5(Lollipop)开始不再支持getRunningTasks和getRunningAppProcesses

As stated, getRunningTasks and getRunningAppProcesses are no longer supported starting with Android 5 (Lollipop)

对于较新的Android版本,您需要要求用户向您授予应用程序使用情况"权限,然后向UsageStatsManager询问在特定时间段内运行的应用程序.

For newer Android versions, you need to ask the user to grant you Apps Usage permission and then ask UsageStatsManager for the apps running in a certain period of time.

https://developer.android.com/reference/android/app/usage/UsageStatsManager.html

您在这里有更多详细信息:

You have more details here:

如何使用UsageStatsManager?

以下是有关如何查询UsageStatsManager的示例(贷记给Cole Murray-在上一个链接中发布)- https://github.com/ColeMurray/UsageStatsSample

Here is a sample on how to query UsageStatsManager (credits to Cole Murray - posted in the previous link) - https://github.com/ColeMurray/UsageStatsSample

这篇关于为什么我无法以编程方式在Android中看到所有正在运行的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆