當前位置: 首頁>>代碼示例>>Java>>正文


Java ActivityManager.RunningAppProcessInfo方法代碼示例

本文整理匯總了Java中android.app.ActivityManager.RunningAppProcessInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java ActivityManager.RunningAppProcessInfo方法的具體用法?Java ActivityManager.RunningAppProcessInfo怎麽用?Java ActivityManager.RunningAppProcessInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.ActivityManager的用法示例。


在下文中一共展示了ActivityManager.RunningAppProcessInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.app.ActivityManager; //導入方法依賴的package包/類
@Override
public void onCreate() {
    mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    // catch up in case we crashed but other processes are still running
    List<ActivityManager.RunningServiceInfo> svcs = mAm.getRunningServices(256);
    for (ActivityManager.RunningServiceInfo svc : svcs) {
        if (svc.service.getPackageName().equals(getPackageName())) {
            Log.v(TAG, "discovered running service: " + svc.process + " (" + svc.pid + ")");
            startTrackingProcess(svc.pid, svc.process,
                    System.currentTimeMillis() - (SystemClock.elapsedRealtime() - svc.activeSince));
        }
    }

    List<ActivityManager.RunningAppProcessInfo> procs = mAm.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo proc : procs) {
        final String pname = proc.processName;
        if (pname.startsWith(getPackageName())) {
            Log.v(TAG, "discovered other running process: " + pname + " (" + proc.pid + ")");
            startTrackingProcess(proc.pid, pname, System.currentTimeMillis());
        }
    }
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:24,代碼來源:MemoryTracker.java

示例2: getProcessName

import android.app.ActivityManager; //導入方法依賴的package包/類
private String getProcessName(Context context) {
    try {
        int pid = android.os.Process.myPid();
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> runningProcess = am.getRunningAppProcesses();
        StringBuilder stringBuilder = new StringBuilder();
        int size = runningProcess.size();
        for (int i = 0; i < size; i++) {
            ActivityManager.RunningAppProcessInfo info = runningProcess.get(i);
            if (info.pid == pid) {
                stringBuilder.append(info.processName);
            }
        }
        return stringBuilder.toString();
    } catch (Exception e) {
    }
    return "";
}
 
開發者ID:waylife,項目名稱:ViewDebugHelper,代碼行數:19,代碼來源:CrashHandler.java

示例3: isAppIsInBackground

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * Method checks if the app is in background or not
 */
public static 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:StringflowServer,項目名稱:Beach-Android,代碼行數:28,代碼來源:NotificationUtils.java

示例4: getAllBackgroundProcesses

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 獲取後台服務進程
 * <p>需添加權限 {@code <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>}</p>
 *
 * @return 後台服務進程
 */
public static Set<String> getAllBackgroundProcesses() {
    ActivityManager am = (ActivityManager) Utils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> info = am.getRunningAppProcesses();
    Set<String> set = new HashSet<>();
    for (ActivityManager.RunningAppProcessInfo aInfo : info) {
        Collections.addAll(set, aInfo.pkgList);
    }
    return set;
}
 
開發者ID:pan2yong22,項目名稱:AndroidUtilCode-master,代碼行數:16,代碼來源:ProcessUtils.java

示例5: isAppInForeground

import android.app.ActivityManager; //導入方法依賴的package包/類
private static boolean isAppInForeground (Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
        return false;
    }
    final String packageName = context.getPackageName();
    for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) {
            return true;
        }
    }
    return false;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:CountlyMessagingService.java

示例6: getProcessName

import android.app.ActivityManager; //導入方法依賴的package包/類
private String getProcessName(int pid) {
    for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
        if (info.pid == pid) {
            return info.processName;
        }
    }
    return null;
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:9,代碼來源:VActivityManagerService.java

示例7: getRunningAppProcessesHandleException

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
     * Android5.0及以上版本,{@link ActivityManager#getRunningAppProcesses()}隻能讀取到自己的進程信息;
     *
     * @param activityManager
     * @return
     */
    private static List<ActivityManager.RunningAppProcessInfo> getRunningAppProcessesHandleException(ActivityManager activityManager) {
        List<ActivityManager.RunningAppProcessInfo> processInfos = null;
        if (activityManager != null) {
            try {
                processInfos = activityManager.getRunningAppProcesses();
            } catch (RuntimeException e) {
                if (Build.VERSION.SDK_INT >= AndroidVersionCodes.N) { // Android7.0
//                    lge LG-H860 7.0(24)、motorola Moto G 7.1(25)、Xiaomi Mi-4c 7.0(24)、Sony F8132 7.0(24)
//                    java.lang.RuntimeException: An error occurred while executing doInBackground()
//                    at android.os.AsyncTask$3.done(AsyncTask.java:318)
//                    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
//                    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
//                    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
//                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
//                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
//                    at java.lang.Thread.run(Thread.java:761)
//                    Caused by: java.lang.RuntimeException: android.os.DeadSystemException
//                    at android.app.ActivityManager.getRunningAppProcesses(ActivityManager.java:3024)
//                    at com.qihoo.utils.AndroidUtilsCompat.getTopPkgNameByActivityManager(AppStore:320)
//                    at com.qihoo.utils.AndroidUtilsCompat.getTopPkgName(AppStore:298)
//                    at com.qihoo.appstore.utils.InjectActivityThreadH$StatRunnable.run(AppStore:75)
//                    at com.qihoo.utils.thread.ThreadUtils$1.doInBackground(AppStore:44)
//                    at com.qihoo.utils.thread.ThreadUtils$1.doInBackground(AppStore:38)
//                    at android.os.AsyncTask$2.call(AsyncTask.java:304)
//                    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
//                    ... 3 more
//                    Caused by: android.os.DeadSystemException
//                    ... 11 more
                } else {
                    throw e;
                }
            }
        }
        return processInfos;
    }
 
開發者ID:miLLlulei,項目名稱:Accessibility,代碼行數:42,代碼來源:AndroidUtilsCompat.java

示例8: getCurrentProcessName

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 獲取當前進程名
 */
public static String getCurrentProcessName() {
    int pid = android.os.Process.myPid();
    String processName = "";
    ActivityManager manager = (ActivityManager) UtilManager.getContext().getSystemService(Context.ACTIVITY_SERVICE);
    if (manager != null) {
        for (ActivityManager.RunningAppProcessInfo process : manager.getRunningAppProcesses()) {
            if (process.pid == pid) {
                processName = process.processName;
            }
        }
    }
    return processName;
}
 
開發者ID:sundevin,項目名稱:utilsLibrary,代碼行數:17,代碼來源:AppInfo.java

示例9: isBackgroundRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
private boolean isBackgroundRunning(){

        final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
        if (procInfos != null)
        {
            for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) {
                if (processInfo.processName.equals("com.braunster.androidchatsdk.app")) {
                    Log.d(TAG, "From: " + processInfo.processName + " is working!!!!!!" );
                    return true;
                }
            }
        }
        return false;
    }
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:16,代碼來源:MyFirebaseMessagingService.java

示例10: getProcessName

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 獲取進程名字
 *
 * @param cxt
 * @param pid
 * @return
 */
public static String getProcessName(Context cxt, int pid) {
    ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
    if (runningApps == null) {
        return null;
    }
    for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
        if (procInfo.pid == pid) {
            return procInfo.processName;
        }
    }
    return null;
}
 
開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:21,代碼來源:AppUtil.java

示例11: isTop

import android.app.ActivityManager; //導入方法依賴的package包/類
public static boolean isTop(Context context) {
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager
            .getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.processName.equals(context.getPackageName())) {
            return appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
        }
    }
    return false;
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:13,代碼來源:AppUtil.java

示例12: 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")) {
            return info;
        }
    }

    return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:RealmInterprocessTest.java

示例13: isMainProcess

import android.app.ActivityManager; //導入方法依賴的package包/類
public boolean isMainProcess() {
    ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));
    List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
    String mainProcessName = getPackageName();
    int myPid = android.os.Process.myPid();
    for (ActivityManager.RunningAppProcessInfo info : processInfos) {
        if (info.pid == myPid && mainProcessName.equals(info.processName)) {
            return true;
        }
    }
    return false;
}
 
開發者ID:linsir6,項目名稱:TripBuyer,代碼行數:13,代碼來源:BaseApplication.java

示例14: resetPackagerOtherProcess

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 重啟當前包名下的其他進程
 *
 * @param context
 */
public static void resetPackagerOtherProcess(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo ai : am.getRunningAppProcesses()) {
        if (ai.uid == android.os.Process.myUid() && ai.pid != android.os.Process.myPid()) {
            android.os.Process.killProcess(ai.pid);
        }
    }
}
 
開發者ID:ireaderlab,項目名稱:ZeusHotfix,代碼行數:14,代碼來源:Util.java

示例15: getRunningAppProcessesNoThrows

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 無需拋出異常而調用getRunningAppProcesses方法
 * @param context context對象
 * @return RunningAppProcessInfo列表
 */
public static List<ActivityManager.RunningAppProcessInfo> getRunningAppProcessesNoThrows(Context context) {
    try {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        return am.getRunningAppProcesses();
    } catch (Throwable e) {
        // 可能AMS掛了,但最多返回空列表即可。畢竟不是很重要的流程
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:16,代碼來源:AMSUtils.java


注:本文中的android.app.ActivityManager.RunningAppProcessInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。