c# - Xamarin 安卓 : Get ALL processes located in memory

标签 c# process xamarin.android

有没有办法读出所有进程,而不仅仅是正在运行的进程。

如果我对 Android 的理解正确的话,一次只有一个进程在运行,其他所有进程都被卡住(后台进程被忽略)

最佳答案

您可以使用以下代码片段获取当前正在运行的所有 android 应用程序进程:

ActivityManager activityManager = (ActivityManager)BaseContext.GetSystemService(Context.ActivityService);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.GetMemoryInfo(memoryInfo);

List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager.RunningAppProcesses as List<ActivityManager.RunningAppProcessInfo>;

然后您可以遍历名为 runningAppProcesses 的列表,并在需要时查询进程信息类以获取其他信息,这些信息可以是 found listed here.

举几个例子:

  • ProcessName - 与此对象关联的进程的名称。

  • Pid - 此进程的 pid; 0 如果没有。

  • Uid - 此进程的用户 ID。

编辑:

根据下面的操作评论,他们需要“卡住”(暂停)进程,这里有一些附加信息:

以前你可以抓取一个正在运行的任务列表,和进程不太一样,但是android定义为:

Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. Note that "running" does not mean any of the task's code is currently loaded or activity -- the task may have been frozen by the system, so that it can be restarted in its previous state when next brought to the foreground.

List<ActivityManager.RunningTaskInfo>

然而,根据 android 文档,此功能在 API 级别 21 中已弃用。

As of Build.VERSION_CODES.LOLLIPOP, this method is no longer available to third party applications: the introduction of document-centric recents means it can leak person information to the caller. For backwards compatibility, it will still return a small subset of its data: at least the caller's own tasks, and possibly some other tasks such as home that are known to not be sensitive.

由于上述 Android 引用的原因,我认为您无法做您想做的事,有关更多信息,您可以前往 this link.

关于c# - Xamarin 安卓 : Get ALL processes located in memory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56621465/

相关文章:

c# - Task.Run 需要很长时间才能启动任务

c# - 从字符串末尾修剪十六进制

C# WinForm 在安装时设置 ConnectionString 和 Entity Framework

c++ - linux进程等待I/O,状态是S+不是D?

linux - PID、PPID和TGID的含义

c# - 等到进程结束

c# - 如果重写时未调用 base.OnCreateView(.....) 会怎样?

c# - xamarin UI 测试 - 无法加载我指向的 native APK 路径

C# 程序集位置解析

android - HttpURLConnection 在 monodroid 上返回 302 错误