當前位置: 首頁>>代碼示例>>Java>>正文


Java RunningAppProcessInfo.IMPORTANCE_FOREGROUND屬性代碼示例

本文整理匯總了Java中android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND屬性的典型用法代碼示例。如果您正苦於以下問題:Java RunningAppProcessInfo.IMPORTANCE_FOREGROUND屬性的具體用法?Java RunningAppProcessInfo.IMPORTANCE_FOREGROUND怎麽用?Java RunningAppProcessInfo.IMPORTANCE_FOREGROUND使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.app.ActivityManager.RunningAppProcessInfo的用法示例。


在下文中一共展示了RunningAppProcessInfo.IMPORTANCE_FOREGROUND屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isAppOnForeground

private boolean isAppOnForeground() { 
    ActivityManager aManager=((ActivityManager)getSystemService(Context.ACTIVITY_SERVICE));
       List<RunningAppProcessInfo> appProcesses = aManager.getRunningAppProcesses(); 
       if (appProcesses == null) return false; 
       for (RunningAppProcessInfo appProcess : appProcesses) { 
           if (appProcess.processName.equals(getPackageName())){
           	    Log.e("StopListennerActivity", "appProcess.importance="+appProcess.importance);
           	   // inRunningTasks(aManager);
           	    if(appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { 
           			return true; 
           		}else{
           			return false;
           		}
           } 
       } 
       return false; 
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:17,代碼來源:StopListennerActivity.java

示例2: isBackground

/**
 * 根據包名判斷應用在前台還是後台
 * 
 * @param context
 * @return
 */
public static boolean isBackground(Context context, String packageName) {
	ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
	for (RunningAppProcessInfo appProcess : appProcesses) {
		if (appProcess.processName.equals(packageName)) {
			if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
				Log.i("前台", appProcess.processName);
				return false;
			} else {
				Log.i("後台", appProcess.processName);
				return true;
			}
		}
	}
	return true;
}
 
開發者ID:teisun,項目名稱:Android-SunmiLauncher,代碼行數:22,代碼來源:ProcessUtils.java

示例3: isAppOnForeground

/**
 * 判斷應用是否在前台顯示
 *
 * @param context     上下文
 * @param packageName 包名
 * @return 返回true表示在前台顯示
 */
public static boolean isAppOnForeground(Context context, String packageName) {
    if (packageName == null || context == null) {
        return false;
    }
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
        return false;
    }
    for (RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.processName.equals(packageName)
                && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            return true;
        }
    }
    return false;
}
 
開發者ID:tengbinlive,項目名稱:ooooim_android,代碼行數:24,代碼來源:CommonUtil.java

示例4: isAppOnForeground

/**
 * 程序是否在前台運行
 * 
 * @return
 */
public static boolean isAppOnForeground(Context context) {
	try {
		ActivityManager activityManager = (ActivityManager) context
				.getApplicationContext().getSystemService(
						Context.ACTIVITY_SERVICE);
		String packageName = context.getPackageName();
		List<RunningAppProcessInfo> appProcesses = activityManager
				.getRunningAppProcesses();
		if (appProcesses == null) {
			return false;
		}
		for (RunningAppProcessInfo appProcess : appProcesses) {
			// The name of the process that this object is associated with.
			if (appProcess.processName.equals(packageName)
					&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
				return true;
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
		LogS.e(TAG, "isAppOnForeground exception!", e);
	}
	return false;
}
 
開發者ID:iQuick,項目名稱:NewsMe,代碼行數:29,代碼來源:AndroidUtil.java

示例5: applicationIsRunning

private boolean applicationIsRunning(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
        List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
        for (RunningAppProcessInfo processInfo : processInfos) {
            if (processInfo.processName.equals(context.getApplicationContext().getPackageName())) {
                if (processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    for (String d: processInfo.pkgList) {
                        Log.v("ReactSystemNotification", "NotificationEventReceiver: ok: " + d);
                        return true;
                    }
                }
            }
        }
    } else {
        List<ActivityManager.RunningTaskInfo> taskInfo = activityManager.getRunningTasks(1);
        ComponentName componentInfo = taskInfo.get(0).topActivity;
        if (componentInfo.getPackageName().equals(context.getPackageName())) {
            return true;
        }
    }

    return false;
}
 
開發者ID:anysome,項目名稱:react-native-pure-notification,代碼行數:25,代碼來源:NotificationEventReceiver.java

示例6: isAppOnForeground

public boolean isAppOnForeground() {
    // Returns a list of application processes that are running on the
    // device
    String packageName = context.getPackageName();
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null)
        return false;
    for (RunningAppProcessInfo appProcess : appProcesses) {
        // importance:
        // The relative importance level that the system places
        // on this process.
        // May be one of IMPORTANCE_FOREGROUND, IMPORTANCE_VISIBLE,
        // IMPORTANCE_SERVICE, IMPORTANCE_BACKGROUND, or IMPORTANCE_EMPTY.
        // These constants are numbered so that "more important" values are
        // always smaller than "less important" values.
        // processName:
        // The name of the process that this object is associated with.
        if (appProcess.processName.equals(packageName) && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            return true;
        }
    }
    return false;
}
 
開發者ID:BigAppOS,項目名稱:BigApp_Discuz_Android,代碼行數:24,代碼來源:ServiceHelper.java

示例7: isBackground

public static boolean isBackground(Context context) {
	ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
	for (RunningAppProcessInfo appProcess : appProcesses) {
		if (appProcess.processName.equals(context.getPackageName())) {
			/*
			 * BACKGROUND=400 EMPTY=500 FOREGROUND=100 GONE=1000
			 * PERCEPTIBLE=130 SERVICE=300 ISIBLE=200
			 */
			Log.i(context.getPackageName(), "此appimportace =" + appProcess.importance
					+ ",context.getClass().getName()=" + context.getClass().getName());
			if (appProcess.importance != RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
				Log.i(context.getPackageName(), "處於後台" + appProcess.processName);
				return true;
			} else {
				Log.i(context.getPackageName(), "處於前台" + appProcess.processName);
				return false;
			}
		}
	}
	return false;
}
 
開發者ID:gizwits,項目名稱:GOpenSource_AppKit_Android_AS,代碼行數:22,代碼來源:NetUtils.java

示例8: isActivityForeground

/**
 * check FM is foreground or background
 */
public boolean isActivityForeground() {
    boolean isForeground = true;
    List<RunningAppProcessInfo> appProcessInfos = mActivityManager.getRunningAppProcesses();
    for (RunningAppProcessInfo appProcessInfo : appProcessInfos) {
        if (appProcessInfo.processName.equals(mContext.getPackageName())) {
            int importance = appProcessInfo.importance;
            Log.d(TAG, "isActivityForeground importance:" + importance);
            if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND ||
                    importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                Log.d(TAG, "isActivityForeground is foreground");
                isForeground = true;
            } else {
                Log.d(TAG, "isActivityForeground is background");
                isForeground = false;
            }
            break;
        }
    }
    Log.d(TAG, "isActivityForeground return " + isForeground);
    return isForeground;
}
 
開發者ID:hyperion70,項目名稱:android_device_MTS_x2605,代碼行數:24,代碼來源:FmRadioService.java

示例9: _IsAppOnForeground

private boolean _IsAppOnForeground()
{
	ActivityManager activityManager = (ActivityManager) getApplicationContext()
			.getSystemService(Context.ACTIVITY_SERVICE);
	String packageName = getApplicationContext().getPackageName();
	List<RunningAppProcessInfo> appProcesses = activityManager
			.getRunningAppProcesses();
	if (appProcesses == null)
		return false;
	for (RunningAppProcessInfo appProcess : appProcesses)
	{
		if (appProcess.processName.equals(packageName)
				&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND)
		{
			return true;
		}
	}
	return false;
}
 
開發者ID:PhoenixCreate,項目名稱:AppPlay,代碼行數:19,代碼來源:AppPlayBaseActivity.java

示例10: isAppInForeground

private boolean isAppInForeground(Context context) 
{
    ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses != null) 
    {
    	final String packageName = context.getPackageName();
        for (RunningAppProcessInfo appProcess : appProcesses) 
        {
Log.i("GCMExtensionProcessList", "running process name = " + appProcess.processName);
        	if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) 
        	{
        		return true;
        	}
        }
    }
    
    return false;
}
 
開發者ID:breealyeska,項目名稱:GCMExtension,代碼行數:19,代碼來源:GCMIntentService.java

示例11: isAppOnForeground

/**
 * 程序是否在前台運行
 * 
 * @return
 */
public boolean isAppOnForeground() {
	ActivityManager activityManager = (ActivityManager) getApplicationContext()
			.getSystemService(Context.ACTIVITY_SERVICE);
	String packageName = getApplicationContext().getPackageName();

	List<RunningAppProcessInfo> appProcesses = activityManager
			.getRunningAppProcesses();
	if (appProcesses == null)
		return false;

	for (RunningAppProcessInfo appProcess : appProcesses) {
		// The name of the process that this object is associated with.
		if (appProcess.processName.equals(packageName)
				&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
			return true;
		}
	}

	return false;
}
 
開發者ID:frankswu,項目名稱:android-saf-plugin-demo,代碼行數:25,代碼來源:BaseFragmentActivity.java

示例12: isApplicationInForeground

private boolean isApplicationInForeground() {
    ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
    if (processInfos != null) {
        for (RunningAppProcessInfo processInfo : processInfos) {
            if (processInfo.processName.equals(getApplication().getPackageName())) {
                if (processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    for (String d : processInfo.pkgList) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
開發者ID:zo0r,項目名稱:react-native-push-notification,代碼行數:16,代碼來源:RNPushNotificationListenerService.java

示例13: isAppOnForeground

private boolean isAppOnForeground() {
	// Returns a list of application processes that are running on the
	// device
	List<RunningAppProcessInfo> appProcesses = activityManager
			.getRunningAppProcesses();
	if (appProcesses == null)
		return false;
	for (RunningAppProcessInfo appProcess : appProcesses) {
		// importance:
		// The relative importance level that the system places
		// on this process.
		// May be one of IMPORTANCE_FOREGROUND, IMPORTANCE_VISIBLE,
		// IMPORTANCE_SERVICE, IMPORTANCE_BACKGROUND, or IMPORTANCE_EMPTY.
		// These constants are numbered so that "more important" values are
		// always smaller than "less important" values.
		// processName:
		// The name of the process that this object is associated with.
		if (appProcess.processName.equals(packageName)
				&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
			return true;
		}
	}
	return false;
}
 
開發者ID:cdkd321,項目名稱:pure,代碼行數:24,代碼來源:BleService.java

示例14: isAppOnForeground

/**
 * 判斷應用是否在前台
 * @return
 */
public boolean isAppOnForeground() {
    ActivityManager activityManager = (ActivityManager) getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    String packageName = getApplicationContext().getPackageName();

    List<RunningAppProcessInfo> appProcesses = activityManager
            .getRunningAppProcesses();
    if (appProcesses == null)
        return false;

    for (RunningAppProcessInfo appProcess : appProcesses) {
        // The name of the process that this object is associated with.
        if (appProcess.processName.equals(packageName)
                && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            return true;
        }
    }

    return false;
}
 
開發者ID:chenjunqian,項目名稱:here,代碼行數:24,代碼來源:BaseActivity.java

示例15: isAppOnForeground

public boolean isAppOnForeground() {
	ActivityManager activityManager = (ActivityManager) getApplicationContext()
			.getSystemService(Context.ACTIVITY_SERVICE);
	String packageName = getApplicationContext().getPackageName();
	List<RunningAppProcessInfo> appProcesses = activityManager
			.getRunningAppProcesses();
	if (appProcesses == null)
		return false;
	for (RunningAppProcessInfo appProcess : appProcesses) {
		if (appProcess.processName.equals(packageName)
				&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
			return true;
		}
	}
	return false;
}
 
開發者ID:AnySDK,項目名稱:Sample_Java,代碼行數:16,代碼來源:MainActivity.java


注:本文中的android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。