当前位置: 首页>>代码示例>>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;未经允许,请勿转载。