如何获取所有已安装的Java应用程序列表?

时间:2014-05-20 18:52:10

标签: java android

在我的示例中,我只有应用程序 - 它自己安装,而不是在系统中显示默认安装的应用程序。

如何更正获取所有应用程序(默认安装)但没有系统进程???

的示例
public ArrayList<String> InstalledApps(String vector)
{
    ArrayList<String> appsList = new ArrayList<String>();
    List<PackageInfo> PackList = getPackageManager().getInstalledPackages(0);
    for (int i=0; i < PackList.size(); i++)
    {
        PackageInfo PackInfo = PackList.get(i);
        if ( ( (PackInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) != true)
        {
            String AppName = PackInfo.applicationInfo.loadLabel(getPackageManager()).toString();
            appsList.add(vector+"::"+PackInfo.packageName+"::"+AppName);
        }
    }
    return appsList;
}

1 个答案:

答案 0 :(得分:0)

感谢帮助人们!!!

我自己找到了一种方法:

public ArrayList<String> InstalledApps(String vector)
{
    PackageManager pm = this.getPackageManager();
    ArrayList<String> appsList = new ArrayList<String>();
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> PackList = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
    for (ResolveInfo rInfo : PackList) {

        String AppName = rInfo.activityInfo.applicationInfo.loadLabel(pm).toString();
        String PackName = rInfo.activityInfo.applicationInfo.packageName;
        if(appsList.contains(PackName)){ continue; }
        appsList.add(vector+"::"+PackName+"::"+AppName);
        }return appsList;
    }