January 16, 2014

定时扫描进程前台是否是属于本应用组件 精确判定当前视图归属

mTask = new TimerTask() {
// 从当前进程队列中提取任务优先级信息存入键值对字典,定时扫描进程前台是否是属于本应用组件
// 精确判定当前视图

@Override
public void run() {
    // Class<?> classN;
    List<?> runninAppProc = actMgr
    .getRunningAppProcesses();
    TreeMap<String, Integer> map = new TreeMap<String, Integer>();
    Iterator<?> iter = runninAppProc
    .iterator();

    while (iter.hasNext()) {
        RunningAppProcessInforunninProcInfo = (RunningAppProcessInfo) iter
        .next();
        Log.d("procInfo","name:"+ runninProcInfo.processName
        .toString()+ "||impID:"+ Integer.toString(runninProcInfo.importance));

        if (iter.hasNext()) {
             map.put(runninProcInfo.processName,             runninProcInfo.importance);
        }

        if (!iter.hasNext()) {
             Log.d("procInfo",
             "===========List Over!===========");
        }

	

	intprio = map.get("com.chinaebi.act");

    if (map.containsKey("com.chinaebi.act")
    && prio == 100) {
        Log.d("判断条件",
        "your apps is foreground!");
        } else {
            displayWindow(SecurityService.this,          R.drawable.background);
            Log.d("判断条件","your app is fadeOut!");
    	}

	}
};
timer.schedule(mTask, 0L, 3380L);