androidpackageinstalled-applications

PackageManager.getInstalledPackages() returns empty list


I am running into a very strange situation when using the PackageManager.getInstalledPackages() method. The first time I launch my activity I get a valid list of all the installed packages. But the second time I launch my activity I get an empty list... What could possibly be causing this?

I am using this code to get the list: List pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

I am building against the 1.6 SDK with compatibility for 1.5+

Thanks in advance for any suggestions/help... I'm really baffled as to the cause and can't think of what I'm doing wrong.


Solution

  • Perhaps the PackageManager needs to be invoked on the main application thread, for some reason. I haven't tried using it from an AsyncTask.

    UPDATE 2018-03-26: PackageManager generally is fine to invoke on background threads, getInstalledPackages() in particular.