So, we all know that the getRecentTasks () and getRunningTasks () functions on the ActivityManager are now deprecated and will return a reduced result set on Android L devices and higher.
Alternative getRunningTasks in Android L
https://code.google.com/p/android-developer-preview/issues/detail?id=29
However, I am trying to find a solution that supports the App Locker application on Android L. I need the name of the top-action package to show the lock screen when users open / launch a locked application.
This is very similar to this application: https://play.google.com/store/apps/details?id=com.domobile.applock&hl=en
I am currently using this code:
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager
.getRunningTasks(1);
ActivityManager.RunningTaskInfo ar = RunningTask.get(0);
String activityOnTop = ar.topActivity.getPackageName();
But it will not work in Android L, so I'm not sure what exactly to do ...
- Android L?