试图获取Android中所有正在运行的任务吗?正在运行、任务、Android

2023-09-08 09:08:38 作者:鱼卷

我试图获取所有当前正在运行的应用程序,我试图做到这一点是这样的:

I am trying to fetch all the currently running apps and i am trying to do it like this:

try
{
    List<ActivityManager.RunningAppProcessInfo> tasks = am.getRunningAppProcesses();
}
catch (SecurityException e)
{
   //Something
}

但每次我试图在模拟器它给我强制关闭错误信息运行它。

But every time i am trying to run it on emulator it's giving me force close error message.

推荐答案

它需要的权限在AndroidManifest.xml中设置:

It need permission to be set in the AndroidManifest.xml:

<uses-permission android:name="android.permission.GET_TASKS" />