I am working on push notification in android where i am using a below method to show notification, but the problem is that now ActivityManager.getRunningTasks(1); is being
May you want this:
/***
* Checking Whether any Activity of Application is running or not
* @param context
* @return
*/
public static boolean isForeground(Context context) {
// Get the Activity Manager
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// Get a list of running tasks, we are only interested in the last one,
// the top most so we give a 1 as parameter so we only get the topmost.
List task = manager.getRunningAppProcesses();
// Get the info we need for comparison.
ComponentName componentInfo = task.get(0).importanceReasonComponent;
// Check if it matches our package name.
if(componentInfo.getPackageName().equals(context.getPackageName()))
return true;
// If not then our app is not on the foreground.
return false;
}