getPackageManager ().getInstalledPackages (PackageManager.GET_ACTIVITIES) returns null

后端 未结 1 1480
无人共我
无人共我 2021-02-04 20:37

If I call

    PackageManager pm = getPackageManager () ;
    List pis = pm.getInstalledPackages (PackageManager.GET_PROVIDERS) ;
相关标签:
1条回答
  • 2021-02-04 20:51

    I came across the same issue and found out a better workaround:

    public void listAllActivities() throws NameNotFoundException
    {
        List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
        for(PackageInfo pack : packages)
        {
            ActivityInfo[] activityInfo = getPackageManager().getPackageInfo(pack.packageName, PackageManager.GET_ACTIVITIES).activities;
            Log.i("Pranay", pack.packageName + " has total " + ((activityInfo==null)?0:activityInfo.length) + " activities");
            if(activityInfo!=null)
            {
                for(int i=0; i<activityInfo.length; i++)
                {
                    Log.i("PC", pack.packageName + " ::: " + activityInfo[i].name);
                }
            }
        }
    }
    

    Notice that I need to query PackageManager twice. Once using getPackageManager().getInstalledPackages(...) and again using getPackageManager().getPackageInfo(...)

    I hope it helps.

    0 讨论(0)
提交回复
热议问题