0

I've tried using this code to fetch the apps that are running in my device:

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();

Log.d("apps", String.valueOf(runningAppProcessInfo));

I thought I would get the names of all the apps that are running in the device. Instead I get this when I debug:

[android.app.ActivityManager$RunningAppProcessInfo@ad46c50]

How do I get the list of all the apps that are presently running?

1 Answers1

-1
final   ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

    for (int i = 0; i < recentTasks.size(); i++) 
    {
        Log.d("Executed app", "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");         
    }

For more information check this link provided.

  • This has not worked since Android 5.0, which came out about seven years ago. See [the documentation](https://developer.android.com/reference/android/app/ActivityManager#getRunningTasks(int)). – CommonsWare Jun 07 '21 at 13:23