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


Java RunningAppProcessInfo类代码示例

本文整理汇总了Java中android.app.ActivityManager.RunningAppProcessInfo的典型用法代码示例。如果您正苦于以下问题:Java RunningAppProcessInfo类的具体用法?Java RunningAppProcessInfo怎么用?Java RunningAppProcessInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: isAppOnForeground

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
@SuppressLint({"NewApi"})
public static boolean isAppOnForeground(Context mContext) {
    ActivityManager activityManager = (ActivityManager) mContext.getSystemService("activity");
    String packageName = mContext.getPackageName();
    LogInfo.log("PushReceiver", "packageName =" + packageName);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
        LogInfo.log("PushReceiver", "------appProcesses == null-----");
        return false;
    }
    for (RunningAppProcessInfo appProcess : appProcesses) {
        LogInfo.log("PushReceiver", "------appProcess.processName =" + appProcess.processName);
        if (appProcess.processName.equals(packageName) && appProcess.importance == 100) {
            for (RunningTaskInfo rti : activityManager.getRunningTasks(100)) {
                if (!(rti == null || rti.baseActivity == null || mContext.getPackageName() == null || !mContext.getPackageName().equals(rti.baseActivity.getPackageName()) || VERSION.SDK_INT < 11)) {
                    activityManager.moveTaskToFront(rti.id, 1);
                }
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:PushNotificationReceiver.java

示例2: isNamedProcess

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
/**
 * whether this process is named with processName
 * 
 * @param context
 * @param processName
 * @return <ul>
 *         return whether this process is named with processName
 *         <li>if context is null, return false</li>
 *         <li>if {@link ActivityManager#getRunningAppProcesses()} is null, return false</li>
 *         <li>if one process of {@link ActivityManager#getRunningAppProcesses()} is equal to processName, return
 *         true, otherwise return false</li>
 *         </ul>
 */
public static boolean isNamedProcess(Context context, String processName) {
    if (context == null) {
        return false;
    }

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

    for (RunningAppProcessInfo processInfo : processInfoList) {
        if (processInfo != null && processInfo.pid == pid
                && ObjectUtils.isEquals(processName, processInfo.processName)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:harrylefit,项目名称:eazycore,代码行数:34,代码来源:AppUtils.java

示例3: getMyProcessName

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的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

示例4: isAcraProcess

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
/**
 * Asks if the current process is "org.fdroid.fdroid:acra".
 * <p>
 * This is helpful for bailing out of the {@link FDroidApp#onCreate} method early, preventing
 * problems that arise from executing the code twice. This happens due to the `android:process`
 * statement in AndroidManifest.xml causes another process to be created to run
 * {@link org.fdroid.fdroid.acra.CrashReportActivity}. This was causing lots of things to be
 * started/run twice including {@link CleanCacheService} and {@link WifiStateChangeService}.
 * <p>
 * Note that it is not perfect, because some devices seem to not provide a list of running app
 * processes when asked. In such situations, F-Droid may regress to the behaviour where some
 * services may run twice and thus cause weirdness or slowness. However that is probably better
 * for end users than experiencing a deterministic crash every time F-Droid is started.
 */
private boolean isAcraProcess() {
    ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
    if (processes == null) {
        return false;
    }

    int pid = android.os.Process.myPid();
    for (RunningAppProcessInfo processInfo : processes) {
        if (processInfo.pid == pid && ACRA_ID.equals(processInfo.processName)) {
            return true;
        }
    }

    return false;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:31,代码来源:FDroidApp.java

示例5: isAppOnForeground

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
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,代码行数:18,代码来源:StopListennerActivity.java

示例6: getProcessName

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
private static String getProcessName(Context context) {
    try {
        String currentProcessName = null;
        int pid = android.os.Process.myPid();

        ActivityManager manager =
                (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
            if (processInfo.pid == pid) {
                currentProcessName = processInfo.processName;
                break;
            }
        }

        return currentProcessName;
    } catch (SecurityException ex) {
        return null;
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:20,代码来源:ChromiumMultiDexInstaller.java

示例7: getCurrentlyRunningMonitoredApps

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
public List<App> getCurrentlyRunningMonitoredApps() {
    List<App> runningMonitoredApps = new ArrayList();
    List<RunningAppProcessInfo> procInfos = ((ActivityManager) this.context.getSystemService("activity")).getRunningAppProcesses();
    if (procInfos != null) {
        for (RunningAppProcessInfo procInfo : procInfos) {
            String processName = procInfo.processName;
            if (!shouldExcludeRunningApp(procInfo)) {
                for (App app : this.appsToMonitor) {
                    if (app.getAppPackageName() != null && app.getAppPackageName().equals(processName)) {
                        runningMonitoredApps.add(app);
                    }
                }
            }
        }
    }
    return runningMonitoredApps;
}
 
开发者ID:bunnyblue,项目名称:NoticeDog,代码行数:18,代码来源:AppMonitor.java

示例8: shouldExcludeRunningApp

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
boolean shouldExcludeRunningApp(RunningAppProcessInfo procInfo) {
    try {
        int flags = RunningAppProcessInfo.class.getField("flags").getInt(procInfo);
        if (procInfo.importance != 100) {
            return true;
        }
        if ((flags & 2) == 2) {
            return true;
        }
        if ((flags & 4) == 0) {
            return true;
        }
        return false;
    } catch (NoSuchFieldException e) {
        return true;
    } catch (IllegalAccessException e2) {
        return true;
    }
}
 
开发者ID:bunnyblue,项目名称:NoticeDog,代码行数:20,代码来源:AppMonitor.java

示例9: isNamedProcess

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
/**
 * whether this process is named with processName
 *
 * @param context     上下文
 * @param processName 进程名
 * @return <ul>
 * return whether this process is named with processName
 * <li>if context is null, return false</li>
 * <li>if {@link ActivityManager#getRunningAppProcesses()} is null,
 * return false</li>
 * <li>if one process of
 * {@link ActivityManager#getRunningAppProcesses()} is equal to
 * processName, return true, otherwise return false</li>
 * </ul>
 */
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<RunningAppProcessInfo> processInfoList = manager
            .getRunningAppProcesses();
    if (processInfoList == null) {
        return true;
    }

    for (RunningAppProcessInfo processInfo : manager
            .getRunningAppProcesses()) {
        if (processInfo.pid == pid
                && processName.equalsIgnoreCase(processInfo.processName)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:huashengzzz,项目名称:SmartChart,代码行数:39,代码来源:AppUtils.java

示例10: checkIsMainProcess

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
public static boolean checkIsMainProcess(Application app) {
    ActivityManager activityManager = (ActivityManager) app.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> runningAppProcessInfoList = activityManager.getRunningAppProcesses();
    if (null == runningAppProcessInfoList) {
        return false;
    }

    String currProcessName = null;
    int currPid = android.os.Process.myPid();
    //find the process name
    for (RunningAppProcessInfo processInfo : runningAppProcessInfoList) {
        if (null != processInfo && processInfo.pid == currPid) {
            currProcessName = processInfo.processName;
        }
    }

    //is current process the main process
    if (!TextUtils.equals(currProcessName, app.getPackageName())) {
        return false;
    }

    return true;
}
 
开发者ID:zyc945,项目名称:AppVisibilityDetector,代码行数:24,代码来源:AppVisibilityDetector.java

示例11: waitKilled

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
private static final void waitKilled(int pid) {
    for (int i = 0; i < 10; i++) {
        try {
            Thread.sleep(100, 0);
        } catch (Throwable e) {
            //
        }
        //
        List<RunningAppProcessInfo> processes = AMSUtils.getRunningAppProcessesNoThrows(RePluginInternal.getAppContext());
        if (processes == null || processes.isEmpty()) {
            continue;
        }
        boolean found = false;
        for (RunningAppProcessInfo info : processes) {
            if (info.pid == pid) {
                found = true;
            }
        }
        if (!found) {
            return;
        }
    }
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:24,代码来源:PluginProcessMain.java

示例12: killBackgroundProcesses

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的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

示例13: getCurrentProcessName

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
public static String getCurrentProcessName(Context context) {
    if (context == null)
        return sCurrentProcessName;

    synchronized (sGetCurrentProcessNameLock) {
        if (sCurrentProcessName == null) {
            ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            List<RunningAppProcessInfo> infos = activityManager.getRunningAppProcesses();
            if (infos == null)
                return null;

            for (RunningAppProcessInfo info : infos) {
                if (info.pid == android.os.Process.myPid()) {
                    sCurrentProcessName = info.processName;
                    return sCurrentProcessName;
                }
            }
        }
    }
    return sCurrentProcessName;
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:22,代码来源:PluginProcessManager.java

示例14: doGc

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
private void doGc(RunningAppProcessInfo myInfo) {
    int activityCount = mRunningProcessList.getActivityCountByPid(myInfo.pid);
    int serviceCount = mRunningProcessList.getServiceCountByPid(myInfo.pid);
    int providerCount = mRunningProcessList.getProviderCountByPid(myInfo.pid);
    if (activityCount <= 0 && serviceCount <= 0 && providerCount <= 0) {
        //杀死空进程。
        Log.i(TAG, "doGc kill process(pid=%s,uid=%s processName=%s)", myInfo.pid, myInfo.uid, myInfo.processName);
        try {
            android.os.Process.killProcess(myInfo.pid);
        } catch (Throwable e) {
            Log.e(TAG, "error on killProcess", e);
        }
    } else if (activityCount <= 0 && serviceCount > 0 /*&& !mRunningProcessList.isPersistentApplication(myInfo.pid)*/) {
        List<String> names = mRunningProcessList.getStubServiceByPid(myInfo.pid);
        if (names != null && names.size() > 0) {
            for (String name : names) {
                Intent service = new Intent();
                service.setClassName(mHostContext.getPackageName(), name);
                AbstractServiceStub.startKillService(mHostContext, service);
                Log.i(TAG, "doGc kill process(pid=%s,uid=%s processName=%s) service=%s", myInfo.pid, myInfo.uid, myInfo.processName, service);
            }
        }
    }
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:25,代码来源:MyActivityManagerService.java

示例15: isMainProcess

import android.app.ActivityManager.RunningAppProcessInfo; //导入依赖的package包/类
public boolean isMainProcess(Context context) {
    if (context == null) {
        return false;
    }
    Object obj;
    int myPid = Process.myPid();
    for (RunningAppProcessInfo runningAppProcessInfo : ((ActivityManager) context
            .getSystemService(ModelName.ACTIVITY)).getRunningAppProcesses()) {
        if (runningAppProcessInfo.pid == myPid) {
            obj = runningAppProcessInfo.processName;
            break;
        }
    }
    obj = null;
    return context.getPackageName().equals(obj);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:DeviceHelper.java


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