1

我正在使用一段 android 代码来学习如何启动应用程序和制作启动器,但我不知道如何过滤掉诸如 faceunlock 和 facebok 之类的应用程序以获得 htc 感觉以及类似的应用程序

public static List<ApplicationInfo> getInstalledApplication(Context context) {
    PackageManager packageManager = context.getPackageManager();
    Intent main = new Intent(Intent.ACTION_MAIN, null);
    main.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ApplicationInfo> apps = packageManager.getInstalledApplications(0);
    Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(packageManager));
    return apps;
}

我知道我可能是一些简单的错误,但我似乎无法找到它请帮助并解释答案,以便我可以从中学习:如果需要,我会发布更多代码

4

3 回答 3

0

请参见下面的代码:

List<ApplicationInfo> applications = getPackageManager().getInstalledApplications(0);
for (int n=0; n < applications.size(); n++)
{
    if ((applications.get(n).applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
    {
        //This is System application
    }
    else
    {
       //This app is installed by user
    }
}
于 2013-11-05T09:45:12.337 回答
0

没关系,经过长时间的搜索,我找到了答案,所以我决定提出来帮助其他有同样问题的人

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;
}

我最终所做的只是替换了我最初为此使用的代码并导入了迭代器并过滤了所有不需要的应用程序:) 希望这可以帮助其他人

于 2013-11-05T21:19:17.147 回答
-1

You can differentiate between system apps and installed apps using Flags available in Package Manager.

PackageManager manager = getPackageManager();
List<PackageInfo> availableActivities = manager.getInstalledPackages(0);

for(PackageInfo packageInfo : availableActivities) {

    if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
        continue;
    }
    else {
        //Installed Apps
    }
}
于 2017-10-05T12:30:11.900 回答