I Am Developing an App where I need to recognise the current running app on top, so I have tried with below code
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
// get the info from the currently running task
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if(!componentInfo.getPackageName().equals("your.package.name"))
{
//Do your stuff
}
But it's not working on Android Lollipop(5.0) and above os version, It's not returning the current running app informations.
please help if any one have any idea to do so on android lollipop(5.0) and above os versions.