當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。