Am Developing an App where i need to recognize 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 its not working on Android Lollipop(5.0) and above, its not returning the current running app information.
please help if any one have any idea to do so on android lollipop(5.0) and above.