如何按降序排序Java中的ArrayList <string>?

时间:2016-07-08 12:35:15

标签: android

我是java新手我试图根据数据使用情况对设备中的安装应用程序列表进行排序。我想在top.i使用代码找到安装包的最高点是:

 List<ApplicationItem> mApplicationItemList = new ArrayList<ApplicationItem>();
    PackageManager p = getPackageManager();
    final List<PackageInfo> apps = p.getInstalledPackages(PackageManager.GET_PERMISSIONS);

            for (PackageInfo packageInfo : apps) {
                ApplicationItem item = new ApplicationItem();
                if (packageInfo.requestedPermissions == null)
                    continue;

                if (Arrays.asList(packageInfo.requestedPermissions).contains(android.Manifest.permission.INTERNET) &&
                        !Utility.isSystemApp(packageInfo.packageName) &&
                        (p.getLaunchIntentForPackage(packageInfo.packageName) != null)) {
                    item.setPkgName(packageInfo.packageName);
                    mApplicationItemList.add(item);
                }
            }
   and find data usage by this code:
public static long getTotalDataByUid(String pkgName) {
        long totalData = 0;
        try {
            ApplicationInfo appInfo = getApplicationContext().getPackageManager().getApplicationInfo(pkgName, 0);
            //TODO Handle UNSUPPORTED
            long tx = TrafficStats.getUidTxBytes(appInfo.uid);
            long rx = TrafficStats.getUidRxBytes(appInfo.uid);
            totalData = tx + rx;
            if (totalData < 0) {
                totalData = 0;
            }


        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            totalData = 0;
        }
        return totalData;
    }

1 个答案:

答案 0 :(得分:0)

使用此方法对arraylist进行排序

"def"