Forum Xamarin Xamarin.Android

Cannot get all RunningAppProcesses

I am trying to get all running app processes. It seems to only be giving me one, which is this current app.

In C#, you have activityManager.RunningAppProcesses. In Java, you have activityManager.getRunningAppProcesses(). The Java code works and gets all processes for all I know, but the C# code only gets one process, and it is the app running the code.

So is there a way where I can get all running app processes like you can in Java? Is the code below correct?

private void getRunningAppProcesses(List<string> collection)
    {
            ActivityManager activityManager = (ActivityManager)GetSystemService("activity");

            if (activityManager != null)
            {
                List<RunningAppProcessInfo> list = new List<RunningAppProcessInfo>();
                list.AddRange(activityManager.RunningAppProcesses);

                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        RunningAppProcessInfo p2 = (RunningAppProcessInfo)list[i];
                        collection.Add(p2.ProcessName);
                    }
                }
            }
    }

Best Answer

Answers

Sign In or Register to comment.