PackageManager.getInstalledApplicationsflag中标准应用程序的哪个标志?

问题描述

当我在Android智能手机上打开Android主菜单时,会看到一系列应用程序,例如Youtube,Calculator,Email client等。那里没有系统内容或任何库。

要通过编程方式检索这些应用,我要做:

PackageManager.getInstalledApplications(flag: Int)  

在这里我得到ApplicationInfo的列表,该列表还包含很多已提到的已安装标准应用程序。我必须设置什么标志才能仅获得相同的应用程序,当我在智能手机上向上滑动时会看到这些应用程序?

解决方法

val mainIntent = Intent(Intent.ACTION_MAIN,null)
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
val appList = context.getPackageManager().queryIntentActivities( mainIntent,0)

您可以尝试获取所有用户应用(以及启动器显示的应用)

不过,您可能需要在Android 10以上的清单中添加其他权限

编辑:如果要在列表中使用ApplicationInfo而不是ResolveInfo,则可以按以下方式检索它:

appList[your_index].activityInfo.applicationInfo

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...