AppHelper

public class AppHelper {

    /**
     * 判断一个应用程序是否正在运行
     * 
     * @param context
     * @param packageName
     *            :应用程序的包名
     * @return
     */
    public static boolean isAppRunning(Context context, String packageName) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
        for (RunningAppProcessInfo rapi : infos) {
            if (rapi.processName.equals(packageName)) {
                return true;
            }
        }
        return false;
    }
}

 

你可能感兴趣的:(help)