Search in sources :

Example 1 with AbAppProcessInfo

use of com.ningcui.mylibrary.model.AbAppProcessInfo in project JustAndroid by chinaltz.

the class AbAppUtil method getRunningAppProcesses.

/**
     * 获取运行的进程列表.
     *
     * @param context
     * @return
     */
public static List<AbAppProcessInfo> getRunningAppProcesses(Context context) {
    ActivityManager activityManager = null;
    List<AbAppProcessInfo> list = null;
    PackageManager packageManager = null;
    try {
        activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        packageManager = context.getApplicationContext().getPackageManager();
        list = new ArrayList<AbAppProcessInfo>();
        //所有运行的进程
        List<RunningAppProcessInfo> appProcessList = activityManager.getRunningAppProcesses();
        ApplicationInfo appInfo = null;
        AbAppProcessInfo abAppProcessInfo = null;
        PackageInfo packageInfo = getPackageInfo(context);
        if (mProcessList != null) {
            mProcessList.clear();
        }
        mProcessList = getProcessRunningInfo();
        for (RunningAppProcessInfo appProcessInfo : appProcessList) {
            abAppProcessInfo = new AbAppProcessInfo(appProcessInfo.processName, appProcessInfo.pid, appProcessInfo.uid);
            appInfo = getApplicationInfo(context, appProcessInfo.processName);
            if (appInfo != null) {
                Drawable icon = appInfo.loadIcon(packageManager);
                String appName = appInfo.loadLabel(packageManager).toString();
                abAppProcessInfo.icon = icon;
                abAppProcessInfo.appName = appName;
            } else {
                //:服务的命名
                if (appProcessInfo.processName.indexOf(":") != -1) {
                    appInfo = getApplicationInfo(context, appProcessInfo.processName.split(":")[0]);
                    Drawable icon = appInfo.loadIcon(packageManager);
                    abAppProcessInfo.icon = icon;
                }
                abAppProcessInfo.appName = appProcessInfo.processName;
            }
            /*AbPsRow psRow = getPsRow(appProcessInfo.processName);
	    		if(psRow!=null){
	    			abAppProcessInfo.memory = psRow.mem;
	    		}*/
            AbProcessInfo processInfo = getMemInfo(appProcessInfo.processName);
            abAppProcessInfo.memory = processInfo.memory;
            abAppProcessInfo.cpu = processInfo.cpu;
            abAppProcessInfo.status = processInfo.status;
            abAppProcessInfo.threadsCount = processInfo.threadsCount;
            list.add(abAppProcessInfo);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list;
}
Also used : AbProcessInfo(com.ningcui.mylibrary.model.AbProcessInfo) PackageInfo(android.content.pm.PackageInfo) AbAppProcessInfo(com.ningcui.mylibrary.model.AbAppProcessInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Drawable(android.graphics.drawable.Drawable) ActivityManager(android.app.ActivityManager) IOException(java.io.IOException) PackageManager(android.content.pm.PackageManager) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo)

Aggregations

ActivityManager (android.app.ActivityManager)1 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Drawable (android.graphics.drawable.Drawable)1 AbAppProcessInfo (com.ningcui.mylibrary.model.AbAppProcessInfo)1 AbProcessInfo (com.ningcui.mylibrary.model.AbProcessInfo)1 IOException (java.io.IOException)1