-1

如何在列表中使用此方法从列表中过滤掉系统包?

我目前有这个方法:

public static List<ApplicationInfo> getInstalledApplication(Context context) {
    PackageManager packageManager = context.getPackageManager();

    List<ApplicationInfo> apps = packageManager.getInstalledApplications(0);
    Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(packageManager));
    return apps;
}

过滤掉系统包的方法:

private boolean isSystemPackage(ResolveInfo ri){
    return ((ri.activityInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)!=0)?true:false;
}
4

1 回答 1

3

这将过滤掉系统包:

public static List<ApplicationInfo> getInstalledApplication(Context context) {
    PackageManager packageManager = context.getPackageManager();
    List<ApplicationInfo> apps = packageManager.getInstalledApplications(0);
    Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(packageManager));
    Iterator<ApplicationInfo> it = apps.iterator();
    while (it.hasNext()) {
        ApplicationInfo ai = it.next();
        if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            it.remove();
        }
    }
    return apps;
}
于 2012-07-23T19:03:45.000 回答