如何获取已安装的应用列表,但不包括系统应用?

时间:2012-11-16 14:16:49

标签: android

  

可能重复:
  How do I check if an app is a non-system app in Android?

目前,此代码会返回所有内容,包括Android系统和时钟等系统应用。

public List<ApplicationInfo> getApps() {
        final PackageManager pm = context.getPackageManager();
        List<ApplicationInfo> packages = pm
                .getInstalledApplications(PackageManager.GET_META_DATA);
        return packages;
    }

如何区分这些应用和用户安装的应用?

1 个答案:

答案 0 :(得分:10)

您好,您可以使用以下代码

 for(ApplicationInfo app : apps) {
        //checks for flags; if flagged, check if updated system app
        if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
            installedApps.add(app);
        //it's a system app, not interested
        } else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
            //Discard this one
        //in this case, it should be a user-installed app
        } else {
            installedApps.add(app);
        }
    }