当前位置: 首页>>代码示例>>Java>>正文


Java ActivityManager.getRunningAppProcesses方法代码示例

本文整理汇总了Java中android.app.ActivityManager.getRunningAppProcesses方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityManager.getRunningAppProcesses方法的具体用法?Java ActivityManager.getRunningAppProcesses怎么用?Java ActivityManager.getRunningAppProcesses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.ActivityManager的用法示例。


在下文中一共展示了ActivityManager.getRunningAppProcesses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isBackground(Context context) {
    if (context == null) {
        return false;
    }

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (activityManager == null) {
        return true;
    }

    List<ActivityManager.RunningAppProcessInfo> appProcesses = null;
    appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null || appProcesses.size() == 0) {
        return false;
    }
    for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.processName.equals(context.getPackageName())) {
            return appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
        }
    }
    return false;
}
 
开发者ID:pre-dem,项目名称:pre-dem-android,代码行数:23,代码来源:Functions.java

示例2: isMainProcess

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * is main process
 *
 * @param context
 * @return
 */
public static boolean isMainProcess(Context context) {
    try {
        ActivityManager am = ((ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE));
        List<ActivityManager.RunningAppProcessInfo> processInfo = am.getRunningAppProcesses();
        String mainProcessName = context.getPackageName();
        int myPid = android.os.Process.myPid();
        for (ActivityManager.RunningAppProcessInfo info : processInfo) {
            if (info.pid == myPid && mainProcessName.equals(info.processName)) {
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:liuzhao2007,项目名称:StartUp-Protector,代码行数:24,代码来源:ProtectorUtils.java

示例3: isNamedProcess

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * whether this process is named with processName
 *
 * @param context     上下文
 * @param processName 进程名
 * @return 是否含有当前的进程
 */
public static boolean isNamedProcess(Context context, String processName) {
    if (context == null || TextUtils.isEmpty(processName)) {
        return false;
    }

    int pid = android.os.Process.myPid();
    ActivityManager manager = (ActivityManager) context.getSystemService(
            Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processInfoList
            = manager.getRunningAppProcesses();
    if (processInfoList == null) {
        return true;
    }

    for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
        if (processInfo.pid == pid &&
                processName.equalsIgnoreCase(processInfo.processName)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:weileng11,项目名称:KUtils-master,代码行数:30,代码来源:Utils.java

示例4: killBackgroundProcesses

import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public boolean killBackgroundProcesses(String pluginPackageName) throws RemoteException {
    ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
    boolean success = false;
    for (RunningAppProcessInfo info : infos) {
        if (info.pkgList != null) {
            String[] pkgListCopy = Arrays.copyOf(info.pkgList, info.pkgList.length);
            Arrays.sort(pkgListCopy);
            if (Arrays.binarySearch(pkgListCopy, pluginPackageName) >= 0 && info.pid != android.os.Process.myPid()) {
                Log.i(TAG, "killBackgroundProcesses(%s),pkgList=%s,pid=%s", pluginPackageName, Arrays.toString(info.pkgList), info.pid);
                android.os.Process.killProcess(info.pid);
                success = true;
            }
        }
    }
    return success;
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:19,代码来源:IPluginManagerImpl.java

示例5: isAppAlive

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 判断应用是否已经启动
 *
 * @param context     一个context
 * @param packageName 要判断应用的包名
 * @return boolean
 */
public static boolean isAppAlive(Context context, String packageName) {
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
    for (int i = 0; i < processInfos.size(); i++) {
        if (processInfos.get(i).processName.equals(packageName)) {
            Log.i("NotificationLaunch",
                    String.format("the %s is running, isAppAlive return true", packageName));
            return true;
        }
    }
    Log.i("NotificationLaunch",
            String.format("the %s is not running, isAppAlive return false", packageName));
    return false;
}
 
开发者ID:liuyongfeng90,项目名称:JKCloud,代码行数:23,代码来源:SystemUtils.java

示例6: getMyProcessName

import android.app.ActivityManager; //导入方法依赖的package包/类
public static String getMyProcessName(Context context) {
    String processName = "";
    ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> infoList = am.getRunningAppProcesses();
    if (infoList == null) {
        throw new RuntimeException("getRunningAppProcesses() returns 'null'.");
    }
    for (RunningAppProcessInfo info : infoList) {
        try {
            if (info.pid == Process.myPid()) {
                processName = info.processName;
                break;
            }
        } catch (Exception ignored) {
        }
    }
    return processName;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:Utils.java

示例7: isAppIsInBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * Method check if app is in background or in foreground
 *
 * @param context this contentx
 * @return true if app is in background or false if app in foreground
 */

private boolean isAppIsInBackground(Context context) {
    boolean isInBackground = true;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
        List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
            if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                for (String activeProcess : processInfo.pkgList) {
                    if (activeProcess.equals(context.getPackageName())) {
                        isInBackground = false;
                    }
                }
            }
        }
    } else {
        List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
        ComponentName componentInfo = taskInfo.get(0).topActivity;
        if (componentInfo.getPackageName().equals(context.getPackageName())) {
            isInBackground = false;
        }
    }

    return isInBackground;
}
 
开发者ID:codingdojoangola,项目名称:cda-app,代码行数:32,代码来源:FirebaseService.java

示例8: isAppAlive

import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isAppAlive(Context context) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> appProcessInfos = activityManager.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo appProcessInfo :
                appProcessInfos
                ) {
                if (appProcessInfo.processName.equals(context.getPackageName())) {
                        LogUtil.e("当前的APP存活");
                        return true;
                }
        }
        return false;
}
 
开发者ID:HelloChenJinJun,项目名称:TestChat,代码行数:14,代码来源:CommonUtils.java

示例9: isAppAlive

import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isAppAlive(Context context, String packageName){
    ActivityManager activityManager =
            (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processInfos
            = activityManager.getRunningAppProcesses();
    for(int i = 0; i < processInfos.size(); i++){
        if(processInfos.get(i).processName.equals(packageName)){
            return true;
        }
    }
    return false;
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:13,代码来源:AppOpener.java

示例10: isCallerForegroundOrSelf

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * @return true when inside a Binder transaction and the caller is in the
 * foreground or self. Don't use outside a Binder transaction.
 */
private boolean isCallerForegroundOrSelf() {
    int uid = Binder.getCallingUid();
    if (uid == Process.myUid()) return true;
    // Starting with L MR1, AM.getRunningAppProcesses doesn't return all the
    // processes. We use a workaround in this case.
    boolean useWorkaround = true;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
        do {
            ActivityManager am =
                    (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE);
            // Extra paranoia here and below, some L 5.0.x devices seem to throw NPE somewhere
            // in this code.
            // See https://crbug.com/654705.
            if (am == null) break;
            List<ActivityManager.RunningAppProcessInfo> running = am.getRunningAppProcesses();
            if (running == null) break;
            for (ActivityManager.RunningAppProcessInfo rpi : running) {
                if (rpi == null) continue;
                boolean matchingUid = rpi.uid == uid;
                boolean isForeground = rpi.importance
                        == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
                useWorkaround &= !matchingUid;
                if (matchingUid && isForeground) return true;
            }
        } while (false);
    }
    return useWorkaround ? !isBackgroundProcess(Binder.getCallingPid()) : false;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:33,代码来源:CustomTabsConnection.java

示例11: isAppForeground

import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isAppForeground() {
    ActivityManager activityManager = (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
        return false;
    }
    final String packageName = mApplication.getPackageName();
    for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.processName.equals(packageName)
                && appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            return true;
        }
    }
    return false;
}
 
开发者ID:TeamThresh,项目名称:Lantern-sdk,代码行数:16,代码来源:RYLA.java

示例12: getCurProcessName

import android.app.ActivityManager; //导入方法依赖的package包/类
public static String getCurProcessName(Context context) {
    int pid = android.os.Process.myPid();
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
        if (appProcess.pid == pid) {
            return appProcess.processName;
        }
    }
    return null;
}
 
开发者ID:zqHero,项目名称:rongyunDemo,代码行数:11,代码来源:App.java

示例13: getRemoteProcessInfo

import android.app.ActivityManager; //导入方法依赖的package包/类
private ActivityManager.RunningAppProcessInfo getRemoteProcessInfo() {
    ActivityManager manager = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo info : processInfoList) {
        if (info.processName.equals(getContext().getPackageName() + REMOTE_PROCESS_POSTFIX)) {
            return info;
        }
    }

    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:RunWithRemoteService.java

示例14: shouldInit

import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean shouldInit() {
    ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));
    List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
    String mainProcessName = getPackageName();
    int myPid = Process.myPid();
    for (ActivityManager.RunningAppProcessInfo info : processInfos) {
        if (info.pid == myPid && mainProcessName.equals(info.processName)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:liuyongfeng90,项目名称:JKCloud,代码行数:13,代码来源:MyApplication.java

示例15: getProcessName

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 获取当前进程名
 * @param context
 * @return 进程名
 */
public static final String getProcessName(Context context) {
    String processName = null;

    // ActivityManager
    ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));

    while (true) {
        for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
            if (info.pid == android.os.Process.myPid()) {
                processName = info.processName;

                break;
            }
        }

        // go home
        if (!TextUtils.isEmpty(processName)) {
            return processName;
        }

        // take a rest and again
        try {
            Thread.sleep(100L);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:34,代码来源:SystemUtil.java


注:本文中的android.app.ActivityManager.getRunningAppProcesses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。