类android.app.ActivityManager.RunningTaskInfo源码实例Demo

下面列出了怎么用android.app.ActivityManager.RunningTaskInfo的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: android_9.0.0_r45   文件: RunningTasks.java
/**
 * Constructs a {@link RunningTaskInfo} from a given {@param task}.
 */
private RunningTaskInfo createRunningTaskInfo(TaskRecord task) {
    task.getNumRunningActivities(mTmpReport);

    final RunningTaskInfo ci = new RunningTaskInfo();
    ci.id = task.taskId;
    ci.stackId = task.getStackId();
    ci.baseActivity = mTmpReport.base.intent.getComponent();
    ci.topActivity = mTmpReport.top.intent.getComponent();
    ci.lastActiveTime = task.lastActiveTime;
    ci.description = task.lastDescription;
    ci.numActivities = mTmpReport.numActivities;
    ci.numRunning = mTmpReport.numRunning;
    ci.supportsSplitScreenMultiWindow = task.supportsSplitScreenWindowingMode();
    ci.resizeMode = task.mResizeMode;
    ci.configuration.setTo(task.getConfiguration());
    return ci;
}
 
源代码2 项目: letv   文件: PushNotificationReceiver.java
@SuppressLint({"NewApi"})
public static boolean isAppOnForeground(Context mContext) {
    ActivityManager activityManager = (ActivityManager) mContext.getSystemService("activity");
    String packageName = mContext.getPackageName();
    LogInfo.log("PushReceiver", "packageName =" + packageName);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
        LogInfo.log("PushReceiver", "------appProcesses == null-----");
        return false;
    }
    for (RunningAppProcessInfo appProcess : appProcesses) {
        LogInfo.log("PushReceiver", "------appProcess.processName =" + appProcess.processName);
        if (appProcess.processName.equals(packageName) && appProcess.importance == 100) {
            for (RunningTaskInfo rti : activityManager.getRunningTasks(100)) {
                if (!(rti == null || rti.baseActivity == null || mContext.getPackageName() == null || !mContext.getPackageName().equals(rti.baseActivity.getPackageName()) || VERSION.SDK_INT < 11)) {
                    activityManager.moveTaskToFront(rti.id, 1);
                }
            }
            return true;
        }
    }
    return false;
}
 
源代码3 项目: letv   文件: PushActivity.java
public final void b() {
    try {
        ActivityManager activityManager = (ActivityManager) getSystemService(z[19]);
        ComponentName componentName = ((RunningTaskInfo) activityManager.getRunningTasks(1).get(0)).baseActivity;
        ComponentName componentName2 = ((RunningTaskInfo) activityManager.getRunningTasks(1).get(0)).topActivity;
        new StringBuilder(z[17]).append(componentName.toString());
        z.b();
        new StringBuilder(z[18]).append(componentName2.toString());
        z.b();
        if (!(componentName == null || componentName2 == null || !componentName2.toString().equals(componentName.toString()))) {
            c();
        }
    } catch (Exception e) {
        c();
    }
    finish();
}
 
源代码4 项目: mobile-manager-tool   文件: PackageUtils.java
/**
 * whether the app whost package's name is packageName is on the top of the stack
 * <ul>
 * <strong>Attentions:</strong>
 * <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
 * </ul>
 * 
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
 *         stack
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || StringUtils.isEmpty(packageName)) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (ListUtils.isEmpty(tasksInfo)) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
源代码5 项目: BaseProject   文件: PackageManagerUtil.java
/**
 * 获取当前堆栈中的第一个activity
 * @param context Context
 * @return 本APP当前运行的栈底组件(Activity)
 * https://blog.csdn.net/u011386173/article/details/79095757 Andorid4.0系列可以,5.0以上机器不行	Android5.0此方法被废弃
 * 对第三方APP无效,但对于获取本应用内的信息是有效的
 */
public static ComponentName getTheProcessBaseActivity(final Context context) {
    ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
    if (activityManager == null) {
        return null;
    }
    List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1);//这里有可能返回的为list size为0
    if (runningTaskInfos == null || runningTaskInfos.isEmpty()) {
        return null;
    }
    RunningTaskInfo task = runningTaskInfos.get(0);
    if (task.numActivities > 0) {
        CommonLog.d(TAG, "runningActivity topActivity=" + task.topActivity.getClassName());
        CommonLog.d(TAG, "runningActivity baseActivity=" + task.baseActivity.getClassName());
        return task.baseActivity;
    }

    return null;
}
 
源代码6 项目: BaseProject   文件: PackageManagerUtil.java
/**
 * 只能获取APP范围内的
 * @param context
 * @return
 */
public static ComponentName[] getAppTopAndBaseActivitys(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
    if (activityManager != null) {
        List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1);
        if (runningTaskInfos != null && runningTaskInfos.size() > 0) {
            RunningTaskInfo topRunningTask = runningTaskInfos.get(0);
            if (topRunningTask != null) {
                if (topRunningTask.numActivities > 0) {
                    CommonLog.e(TAG, "---> getAppTopAndBaseActivitys() top:" + topRunningTask.topActivity/*.getPackageName()*/
                            + "  base:" + topRunningTask.baseActivity
                    );
                    ComponentName[] topAndBaseComponents = {
                            topRunningTask.topActivity,
                            topRunningTask.baseActivity
                    };
                    return topAndBaseComponents;
                }
            }
        }
    }
    return null;
}
 
源代码7 项目: BaseProject   文件: PackageManagerUtil.java
@SuppressLint("MissingPermission")
public static void moveAppTaskToFront(Context context) {
    /**获取ActivityManager*/
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (activityManager == null) {
        return;
    }
    /**获得当前运行的task(任务)*/
    List<ActivityManager.RunningTaskInfo> taskInfoList = activityManager.getRunningTasks(100);
    for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) {
        /**找到本应用的 task,并将它切换到前台*/
        if (taskInfo.topActivity.getPackageName().equals(context.getPackageName())) {
            activityManager.moveTaskToFront(taskInfo.id, 0);
            break;
        }
    }
}
 
源代码8 项目: AndroidStudyDemo   文件: PackageUtil.java
/**
 * whether the app whost package's name is packageName is on the top of the
 * stack
 * <ul>
 * <strong>Attentions:</strong>
 * <li>You should add <strong>android.permission.GET_TASKS</strong> in
 * manifest</li>
 * </ul>
 *
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise
 * retun whether the app is on the top of stack
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || TextUtils.isEmpty(packageName)) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (tasksInfo == null || tasksInfo.size() < 1) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity
                .getPackageName());
    } catch (Exception e) {
        Logger.e(e);
        return false;
    }
}
 
源代码9 项目: AndroidBasicProject   文件: PackageUtil.java
/**
 * 检测应用是否在前台
 *
 * Attentions:
 * <ul>
 * <li>You should add android.permission.GET_TASKS in manifest</li>
 * </ul>
 * 
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
 *         stack
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || DataUtil.isEmpty(packageName)) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (DataUtil.isEmpty(tasksInfo)) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
源代码10 项目: Utils   文件: PackageHelper.java
/**
 * whether the app package's name is on the top of the stack
 * <ul>
 * <strong>Attentions:</strong>
 * <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
 * </ul>
 *
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
 * stack
 */
public static boolean isTopActivity(Context context, String packageName) {
    if (context == null || ObjectHelper.isEmpty(packageName)) {
        return false;
    }

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (ObjectHelper.isEmpty(tasksInfo)) {
        return false;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
源代码11 项目: rootinspector   文件: Root.java
public boolean checkRootMethod11() {
	Log.d(Main.TAG, "check12");
	boolean returnValue = false;
	// Get currently running application processes
	List<RunningTaskInfo> list = manager.getRunningTasks(300);
	if(list != null){
		String tempName;
		for(int i=0;i<list.size();++i){
			tempName = list.get(i).baseActivity.flattenToString();
			Log.d(Main.TAG, "baseActivity: " + tempName);
			if(tempName.contains("supersu") || tempName.contains("superuser")){
				Log.d(Main.TAG, "found one!");
				returnValue = true;
			}
		}
	}
	return returnValue;
}
 
源代码12 项目: UltimateAndroid   文件: PackageUtils.java
/**
 * whether the app whost package's name is packageName is on the top of the stack
 * <ul>
 * Attentions:
 * <li>You should add android.permission.GET_TASKS in manifest</li>
 * </ul>
 *
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
 * stack
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || !BasicUtils.judgeNotNull(packageName)) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (!BasicUtils.judgeNotNull(tasksInfo)) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
源代码13 项目: UltimateAndroid   文件: PackageUtils.java
/**
 * whether the app whost package's name is packageName is on the top of the stack
 * <ul>
 * <strong>Attentions:</strong>
 * <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
 * </ul>
 * 
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
 *         stack
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || BasicUtils.judgeNotNull(packageName)) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (BasicUtils.judgeNotNull(tasksInfo)) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
源代码14 项目: UltimateAndroid   文件: PackageUtils.java
/**
 * whether the app whost package's name is packageName is on the top of the stack
 * <ul>
 * <strong>Attentions:</strong>
 * <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
 * </ul>
 *
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
 * stack
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || !BasicUtils.judgeNotNull(packageName)) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (!BasicUtils.judgeNotNull(tasksInfo)) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
源代码15 项目: SimplePomodoro-android   文件: MyUtils.java
public static ScreenState getScreenState(Context c){
		PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
		boolean isScreenOn = pm.isScreenOn();
		if(isScreenOn){
			ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
			List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(Integer.MAX_VALUE);
			RunningTaskInfo info = runningTaskInfos.get(0);
			String nowPackageName = info.baseActivity.getPackageName();
			if(nowPackageName.equals(MY_PACKAGE_NAME)){
				return ScreenState.MYAPP;
			}else{
				return ScreenState.OTHERAPP;
			}
//			Log.e("MyUtils",nowPackageName);
		}else{
//			Log.e("isScreenOn:",String.valueOf(isScreenOn));
			return ScreenState.LOCK;
		}
	}
 
源代码16 项目: FimiX8-RE   文件: SystemParamUtil.java
public static boolean isTopActivy(String cmdName, Activity activity) {
    List<RunningTaskInfo> runningTaskInfos = ((ActivityManager) activity.getSystemService("activity")).getRunningTasks(1);
    String cmpNameTemp = null;
    if (runningTaskInfos != null) {
        cmpNameTemp = ((RunningTaskInfo) runningTaskInfos.get(0)).topActivity.getClassName();
    }
    if (cmpNameTemp == null) {
        return false;
    }
    return cmpNameTemp.equals(cmdName);
}
 
源代码17 项目: android_9.0.0_r45   文件: RunningTasks.java
void getTasks(int maxNum, List<RunningTaskInfo> list, @ActivityType int ignoreActivityType,
        @WindowingMode int ignoreWindowingMode, SparseArray<ActivityDisplay> activityDisplays,
        int callingUid, boolean allowed) {
    // Return early if there are no tasks to fetch
    if (maxNum <= 0) {
        return;
    }

    // Gather all of the tasks across all of the tasks, and add them to the sorted set
    mTmpSortedSet.clear();
    mTmpStackTasks.clear();
    final int numDisplays = activityDisplays.size();
    for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
        final ActivityDisplay display = activityDisplays.valueAt(displayNdx);
        for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
            final ActivityStack stack = display.getChildAt(stackNdx);
            stack.getRunningTasks(mTmpStackTasks, ignoreActivityType, ignoreWindowingMode,
                    callingUid, allowed);
            for (int i = mTmpStackTasks.size() - 1; i >= 0; i--) {
                mTmpSortedSet.addAll(mTmpStackTasks);
            }
        }
    }

    // Take the first {@param maxNum} tasks and create running task infos for them
    final Iterator<TaskRecord> iter = mTmpSortedSet.iterator();
    while (iter.hasNext()) {
        if (maxNum == 0) {
            break;
        }

        final TaskRecord task = iter.next();
        list.add(createRunningTaskInfo(task));
        maxNum--;
    }
}
 
源代码18 项目: RePlugin-GameSdk   文件: InteractiveService.java
private static String getOldTopActivityPkgName(ActivityManager activityManager) {
	try {
		ActivityManager.RunningTaskInfo info = (ActivityManager.RunningTaskInfo) activityManager.getRunningTasks(1).get(0);
		String packageName = info.topActivity.getPackageName();
		if (packageName == null) {
			return "";
		}
		return packageName;
	} catch (Exception e) {
	}
	return "";
}
 
/**
 * https://stackoverflow.com/questions/5446565/android-how-do-i-check-if-activity-is-running
 *
 * @param context Context
 * @return boolean
 */
public static boolean isRunning(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

    for (RunningTaskInfo task : tasks) {
        if (context.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName()))
            return true;
    }

    return false;
}
 
源代码20 项目: styT   文件: timer.java
public void run() {
	List runningTasks = mWatchingService.mActivityManager.getRunningTasks(1);
	String serviceName = ((RunningTaskInfo) runningTasks.get(0)).topActivity.getPackageName() + "\n"
			+ ((RunningTaskInfo) runningTasks.get(0)).topActivity.getClassName();
	if (!serviceName.equals(mWatchingService.serviceName)) {
		mWatchingService.serviceName = serviceName;
		if (DefaultSharedPreferences.read(mWatchingService)) {
			mWatchingService.mHanlder.post(new RunView(this));
		}
	}
}
 
源代码21 项目: stynico   文件: timer.java
public void run() {
	List runningTasks = mWatchingService.mActivityManager.getRunningTasks(1);
	String serviceName = ((RunningTaskInfo) runningTasks.get(0)).topActivity.getPackageName() + "\n"
			+ ((RunningTaskInfo) runningTasks.get(0)).topActivity.getClassName();
	if (!serviceName.equals(mWatchingService.serviceName)) {
		mWatchingService.serviceName = serviceName;
		if (DefaultSharedPreferences.read(mWatchingService)) {
			mWatchingService.mHanlder.post(new RunView(this));
		}
	}
}
 
源代码22 项目: stynico   文件: NotificationActionReceiver.java
public void onReceive(Context context, Intent intent)
  {
switch (intent.getIntExtra("command", -1))
{
	case 0:
		showNotification(context, true);
		ViewWindow.removeView();
		DefaultSharedPreferences.save(context, false);
		return;
	case 1:
		showNotification(context, false);
		DefaultSharedPreferences.save(context, true);
		if (VERSION.SDK_INT >= 21)
		{
			ViewWindow.showView(context, null);
			return;
		}
		List runningTasks = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1);
		ViewWindow.showView(context, ((RunningTaskInfo) runningTasks.get(0)).topActivity.getPackageName() + "\n"
							+ ((RunningTaskInfo) runningTasks.get(0)).topActivity.getClassName());
		return;
	case 2:
		ViewWindow.removeView();
		DefaultSharedPreferences.save(context, false);
		initNotification(context);
		return;
	default:
		return;
}
  }
 
源代码23 项目: RxEasyHttp   文件: AppTools.java
/**
 * @param @param  context
 * @param @return 设定文件
 * @return String    返回类名
 * @Title: getTopActivity
 * @Description: 获取栈顶activity
 */
@SuppressWarnings("deprecation")
public static String getTopActivity(Context context) {
    ActivityManager manager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);

    if (runningTaskInfos != null)
        return (runningTaskInfos.get(0).topActivity.getClassName());
    else
        return "";
}
 
源代码24 项目: letv   文件: Util.java
public static boolean isBackground(Context context) {
    List<RunningTaskInfo> tasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
    if (tasks.isEmpty() || ((RunningTaskInfo) tasks.get(0)).topActivity.getPackageName().equals(context.getPackageName())) {
        return false;
    }
    return true;
}
 
源代码25 项目: letv   文件: DialogService.java
public boolean isHome() {
    ActivityManager mActivityManager = (ActivityManager) getSystemService("activity");
    List<String> homeList = getHomes();
    List<RunningTaskInfo> rti = mActivityManager.getRunningTasks(1);
    if (homeList != null) {
        return homeList.contains(((RunningTaskInfo) rti.get(0)).topActivity.getPackageName());
    }
    return false;
}
 
源代码26 项目: letv   文件: PushNotificationReceiver.java
@SuppressLint({"NewApi"})
private void pushLiveOver() {
    LetvConstant.setForcePlay(false);
    StatisticsUtils.setActionProperty(NetworkUtils.DELIMITER_LINE, -1, NetworkUtils.DELIMITER_LINE);
    if (MainActivity.getInstance() != null) {
        if (this.isShowToast) {
            UIsUtils.showToast(TipUtils.getTipMessage("70004", 2131100703));
        }
        ActivityManager am = (ActivityManager) this.mContext.getSystemService("activity");
        for (RunningTaskInfo rti : am.getRunningTasks(100)) {
            if (!(rti == null || rti.baseActivity == null || this.mContext.getPackageName() == null || !this.mContext.getPackageName().equals(rti.baseActivity.getPackageName()))) {
                if (VERSION.SDK_INT >= 11) {
                    am.moveTaskToFront(rti.id, 1);
                }
                LogInfo.log("push_", "moveTaskToFront rti.id = " + rti.id);
            }
        }
        if (TextUtils.isEmpty(this.cid)) {
            MainLaunchUtils.launch(MainActivity.getInstance(), true);
        } else if (!(this.cid.equals("3") || this.cid.equals("8") || this.cid.equals("4") || this.cid.equals("9"))) {
            MainLaunchUtils.launch(MainActivity.getInstance(), true);
        }
        LogInfo.log("push_", "pushLiveOver live pushCid " + this.cid);
        return;
    }
    if (TextUtils.isEmpty(this.cid)) {
        MainLaunchUtils.launch(this.mContext, true);
    } else if (this.cid.equals("3")) {
        MainLaunchUtils.launchGotoLive(this.mContext, "ent", null, this.isShowToast, true);
    } else if (this.cid.equals("8")) {
        MainLaunchUtils.launchGotoLive(this.mContext, "other", null, this.isShowToast, true);
    } else if (this.cid.equals("4")) {
        MainLaunchUtils.launchGotoLive(this.mContext, "sports", null, this.isShowToast, true);
    } else if (this.cid.equals("9")) {
        MainLaunchUtils.launchGotoLive(this.mContext, "music", null, this.isShowToast, true);
    } else {
        MainLaunchUtils.launch(this.mContext, true);
    }
    LogInfo.log("push_", "pushLiveOver MainActivity.getInstance() == null no jump to live");
}
 
源代码27 项目: letv   文件: LetvUtil.java
public static boolean isRunningForeground(Context context) {
    String currentPackageName = ((RunningTaskInfo) ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1).get(0)).topActivity.getPackageName();
    String appPackageName = context.getPackageName();
    if (TextUtils.isEmpty(currentPackageName) || !currentPackageName.equals(appPackageName)) {
        return false;
    }
    return true;
}
 
源代码28 项目: letv   文件: LetvUtils.java
public static boolean isApplicationInBackground(Context context) {
    List<RunningTaskInfo> tasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
    if (tasks.isEmpty() || ((RunningTaskInfo) tasks.get(0)).topActivity.getPackageName().equals(context.getPackageName())) {
        return false;
    }
    return true;
}
 
源代码29 项目: letv   文件: LetvUtils.java
public static boolean isTopRunning(Context context) {
    List<RunningTaskInfo> tasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
    if (!tasks.isEmpty()) {
        ComponentName topActivity = ((RunningTaskInfo) tasks.get(0)).topActivity;
        LogInfo.log("plugin", "topActivity = " + topActivity.toString());
        LogInfo.log("plugin", "topActivity.getPackageName() = " + topActivity.getPackageName());
        LogInfo.log("plugin", "context.getPackageName() = " + context.getPackageName());
        if (topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }
    }
    return false;
}
 
源代码30 项目: letv   文件: IRMonitor.java
private static boolean k(Context context) {
    try {
        if (d.b(context, "android.permission.GET_TASKS")) {
            List runningTasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
            if (!(runningTasks == null || runningTasks.isEmpty())) {
                return ((RunningTaskInfo) runningTasks.get(0)).topActivity.getPackageName().equals(context.getPackageName());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
 类所在包
 同包方法