I tried a lot to get the list of recent and running applications(not processes) but couldn\'t get it.
I went through all the stackoverflow questions regarding this b
For api level < 21
You need this permission:
And this code:
ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List recentTasks = activityManager.getRecentTasks(10, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
for (ActivityManager.RecentTaskInfo recentTask : recentTasks) {
try {
String packageName = recentTask.baseIntent.getComponent().getPackageName();
ApplicationInfo appInfo = getPackageManager().getApplicationInfo(packageName, PackageManager.GET_META_DATA);
String label = getPackageManager().getApplicationLabel(appInfo).toString();
Log.i("APPS", label);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}