Below is the code I run to get the processes that were running on the Android device. But the catch is i get it along with all the system processes. Is there a way to separate the System Servies (or) can I change the function call so that I dont get the system services altogether.
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public List<UsageStats> getUsageStats() {
UsageStatsManager mUsageStatsManager = (UsageStatsManager) getActivity()
.getSystemService(Context.USAGE_STATS_SERVICE);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY,0);
cal.set(Calendar.MINUTE,1);
List<UsageStats> queryUsageStats = mUsageStatsManager
.queryUsageStats(UsageStatsManager.INTERVAL_BEST, cal.getTimeInMillis(),
System.currentTimeMillis());
return queryUsageStats;
}
What I do is to convert the each result from queryusageStats into a package name and then filter them out. If the package is a user installed package then it will have a proper name else it will be printed as null. I am also not able to find any straight way forward so had to work around this.
For example: