getRunningAppProcesses()仅返回我的应用程序

时间:2017-09-12 11:35:15

标签: java android

我使用此方法在后台运行所有正在运行的应用程序进程

        list = new ArrayList<AppProcessInfo>();
            ApplicationInfo appInfo = null;
            AppProcessInfo abAppProcessInfo = null;

            List<ActivityManager.RunningAppProcessInfo> appProcessList = activityManager
                    .getRunningAppProcesses();
      //      publishProgress(0, appProcessList.size());

            for (ActivityManager.RunningAppProcessInfo appProcessInfo : appProcessList) {
         //       publishProgress(++mAppCount, appProcessList.size());
                abAppProcessInfo = new AppProcessInfo(
                        appProcessInfo.processName, appProcessInfo.pid,
                        appProcessInfo.uid);
                try {
                    appInfo = packageManager.getApplicationInfo(appProcessInfo.processName, 0);
    ...........................
.............................

但是当我在我的设备中运行我的应用程序(android 6.0)时我只得到我的应用程序进程可以任何人帮助修改此功能工作 我看到这个https://github.com/jaredrummler/AndroidProcesses 但我不知道如何使用它,因为我在我的功能中使用不同的结构?

1 个答案:

答案 0 :(得分:0)

我使用这个库 https://github.com/jaredrummler/AndroidProcesses/ 我将我的代码更新到此

list = new ArrayList<AppProcessInfo>();
        ApplicationInfo appInfo = null;
        AppProcessInfo abAppProcessInfo = null;

        List<ActivityManager.RunningAppProcessInfo> appProcessList = activityManager
                .getRunningAppProcesses();
  //      publishProgress(0, appProcessList.size());
        List<AndroidAppProcess> processes = AndroidProcesses.getRunningAppProcesses();

        for (AndroidAppProcess appProcessInfo : processes) {

            String processName = appProcessInfo.name;

            Stat stat = null;
            try {
                stat = appProcessInfo.stat();
            } catch (IOException e) {
                e.printStackTrace();
            }

            abAppProcessInfo = new AppProcessInfo(
                    appProcessInfo.name, stat.getPid(),
                    appProcessInfo.uid);
            try {
                appInfo = appProcessInfo.getPackageInfo(mContext, 0).applicationInfo;
.........................
它现在正在工作 谢谢