The inspection process is running at the top - Android android.app

Android examples for android.app:ActivityManager

Description

The inspection process is running at the top

Demo Code

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ComponentName;
import android.content.Context;

public class Main {

  public static boolean isForeground(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> list = activityManager.getRunningTasks(1);
    ComponentName cn = list.get(0).topActivity;
    String name = cn.getPackageName();

    return name.indexOf(context.getPackageName()) > -1;
  }//from w  w  w . j av a2 s  .c  o m

}

Related Tutorials