Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why i can't see all Running Apps in Android Programmatically?

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();

Many sites tells to use

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

But also just returned my application

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

like image 572
Gorio Avatar asked Oct 18 '22 07:10

Gorio


1 Answers

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

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:

How to use UsageStatsManager?

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

like image 112
Mihai Neacsu Avatar answered Oct 21 '22 06:10

Mihai Neacsu