PackageManager.getInstalledPackages () returns an empty list

I am facing a very strange situation when using the PackageManager.getInstalledPackages () method. The first time I start my activity, I get a valid list of all installed packages. But the second time I start my activity, I get an empty list ... What could be the reason for this?

I use this code to get the list: List pkgList = getPackageManager (). GetInstalledPackages (PackageManager.GET_ACTIVITIES);

I am building against 1.6 SDK with compatibility for 1.5+

Thanks in advance for any suggestions / help ... I am really puzzled by the reason and can't think of what I'm doing wrong.

+2
source share
2 answers

Perhaps for some reason you need to call for the main application flow PackageManager. I have not tried using it with AsyncTask.

UPDATE 2018-03-26 : PackageManagerin general, it is normal to start background threads, in particular getInstalledPackages().

+3
source

You get an empty list because the PackageManager is dead, because the IPC buffer used to return the list of installed applications has grown larger than the buffer size of 1 MB (according to version 4.4).

Starting with API 15, the same behavior will generate TransactionTooLargeException. In API <15, only an empty list is returned, and sometimes a small error is visible in logcats.

getInstalledPackages() . , . , , , IPC- .

+1

All Articles