getRunningAppProcesses返回在Android中号空列表(5.1.1) [英] getRunningAppProcesses returns empty list on Android M(5.1.1)

查看:947
本文介绍了getRunningAppProcesses返回在Android中号空列表(5.1.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是测试我的应用程序和CM,ATM Android的助理,等等。所有这些都无法得到正在运行的进程列表,但他们正常工作的pre OS版本。所以,这是怎么回事了Android M(5.1.1)?请大家帮忙!

  AM =(ActivityManager)的getContext()getSystemService(Context.ACTIVITY_SERVICE)。
名单< RunningAppProcessInfo>表= am.getRunningAppProcesses();
Log.i(TAG,LQ ::检查则为list.size()=+则为list.size());
 

解决方案

我决定使用getRunningServices,而不是!

杜速度的助推器和放大器;电源清洁使用getRunningServices代替,也许getRunningAppProcesses是pcated在未来去$ P $。

感谢您谷歌,谢谢字母表。

 的Hashtable<字符串列表与LT; ActivityManager.RunningServiceInfo>>哈希表=新的Hashtable<字符串列表与LT; ActivityManager.RunningServiceInfo>>();
    ActivityManager AM =(ActivityManager)的getContext()getSystemService(Context.ACTIVITY_SERVICE)。
    对于(ActivityManager.RunningServiceInfo RSI:am.getRunningServices(Integer.MAX_VALUE的)){
        如果(isCanceled()){
            返回;
        }

        字符串PKGNAME = rsi.service.getPackageName();
        如果(hashtable.get(包名称)== NULL){
            名单< ActivityManager.RunningServiceInfo>名单=新的ArrayList< ActivityManager.RunningServiceInfo>();
            list.add(RSI);
            hashtable.put(PKGNAME,清单);
        } 其他 {
            hashtable.get(PKGNAME)。新增(RSI);
        }
    }

    INT I = 0;
    INT大小= hashtable.size();
    对于(迭代它= hashtable.keySet()迭代器(); it.hasNext();我++){
        字符串键=(字符串)it.next();
        名单< ActivityManager.RunningServiceInfo>值= hashtable.get(密钥);
        ProcessItem项目=新ProcessItem(的getContext(),value.get(0).pid,钥匙,totalCpu,totalRam);
        如果(!whiteList.contains(item.pkgName)){
            如果(!killList.contains(item.pkgName)){
                killList.add(item.pkgName);
                ramTotal + = item.ram;

                如果(getListener()!= NULL){
                    进度进度=新进展(本);
                    progress.setArg1(ⅰ);
                    progress.setArg2(大小);
                    progress.setMsg(item.appName);
                    progress.setObj(项目);
                    getListener()onExamining(进度)。
                }
            }
        }
    }
    hashtable.clear();
    哈希表= NULL;
 

I just tested my app and CM, ATM Android Assistant, etc. All of them can not get the running process list but they works fine on pre OS version. So what's going on with Android M(5.1.1)? please help!

am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> list = am.getRunningAppProcesses();
Log.i(TAG, "LQ::examine list.size()=" + list.size());

解决方案

I decide to use getRunningServices instead!

Du Speed Booster & Power Clean uses getRunningServices instead, maybe getRunningAppProcesses is deprecated in future.

Thank you google, thank you alphabet.

    Hashtable<String, List<ActivityManager.RunningServiceInfo>> hashtable = new Hashtable<String, List<ActivityManager.RunningServiceInfo>>();
    ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo rsi : am.getRunningServices(Integer.MAX_VALUE)) {
        if (isCanceled()) {
            return;
        }

        String pkgName = rsi.service.getPackageName();
        if (hashtable.get(pkgName) == null) {
            List<ActivityManager.RunningServiceInfo> list = new ArrayList<ActivityManager.RunningServiceInfo>();
            list.add(rsi);
            hashtable.put(pkgName, list);
        } else {
            hashtable.get(pkgName).add(rsi);
        }
    }

    int i = 0;
    int size =  hashtable.size();
    for (Iterator it = hashtable.keySet().iterator(); it.hasNext(); i++) {
        String key = (String) it.next();
        List<ActivityManager.RunningServiceInfo> value = hashtable.get(key);
        ProcessItem item = new ProcessItem(getContext(), value.get(0).pid, key, totalCpu, totalRam);
        if (!whiteList.contains(item.pkgName)) {
            if (!killList.contains(item.pkgName)) {
                killList.add(item.pkgName);
                ramTotal += item.ram;

                if (getListener() != null) {
                    Progress progress = new Progress(this);
                    progress.setArg1(i);
                    progress.setArg2(size);
                    progress.setMsg(item.appName);
                    progress.setObj(item);
                    getListener().onExamining(progress);
                }
            }
        }
    }
    hashtable.clear();
    hashtable = null;

这篇关于getRunningAppProcesses返回在Android中号空列表(5.1.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆