获取进程

private String getProcessName(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List runningApps = am.getRunningAppProcesses();

    if (runningApps == null) {

        return null;

    }

    for (ActivityManager.RunningAppProcessInfo proInfo : runningApps) {

        if (proInfo.pid == android.os.Process.myPid()) {

            if (proInfo.processName != null) {

                return proInfo.processName;

            }

        }

    }

    return null;
}

你可能感兴趣的:(获取进程)