PackageManager.getInstalledPackages() 返回空列表

时间:2023-01-31
本文介绍了PackageManager.getInstalledPackages() 返回空列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在使用 PackageManager.getInstalledPackages() 方法时遇到了一个非常奇怪的情况.第一次启动我的活动时,我会得到所有已安装软件包的有效列表.但是第二次启动我的活动时,我得到一个空列表...可能是什么原因造成的?

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?

我正在使用此代码来获取列表:列出 pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

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

我正在构建与 1.5+ 兼容的 1.6 SDK

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.

推荐答案

可能出于某种原因需要在主应用程序线程上调用 PackageManager.我没有尝试从 AsyncTask 中使用它.

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 通常可以在后台线程上调用,尤其是 getInstalledPackages().

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

这篇关于PackageManager.getInstalledPackages() 返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:PreferenceScreen 中不同包的 targetClass 时的 ActivityNotFoundExcept 下一篇:android 在已删除的包中没有收到 Intent ACTION_PACKAGE_REMOVED

相关文章

最新文章