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

后端 未结 1 1482
无人共我
无人共我 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 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

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

    I hope it helps.

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